What's the point of new String(“x”) in JavaScript?

后端 未结 9 1806
走了就别回头了
走了就别回头了 2020-11-30 04:21

What are the use cases for doing new String(\"already a string\")?

What\'s the whole point of it?

9条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-30 05:27

    Javascript creators created wrappers for basic types like string or int just to make it similar to java. Unfortunately, if someome makes new String("x") the type of the element will be "object" and not "string".

    var j = new String("x");
    j === "x"  //false
    j == "x" //true
    

提交回复
热议问题