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

后端 未结 9 1820
走了就别回头了
走了就别回头了 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:20

    Why do you need to check if it is string?

    Just check if it is defined or null, and otherwise defensively convert it to any type you want, either the var bar = new String(foo); or var bar = "" + foo;.

提交回复
热议问题