javascript - how to get an object to return a value that is not the object itself

前端 未结 4 735
情歌与酒
情歌与酒 2021-01-23 18:07

When creating a x = new Date() object, if you put it into console.log(x) a string will be output.

Is there a way to make a custom object that w

4条回答
  •  北海茫月
    2021-01-23 18:49

    You can convert most of the objects to string as follows

    String(object)
    

    like

    x = String(new Date()); // now x is a string 
    

    Similarly

    x = Boolean(0); // wil return an object
    x = String(Boolean(0)); // will return a string
    

提交回复
热议问题