JavaScript string initialization

后端 未结 5 572
暗喜
暗喜 2021-02-04 08:39

In JavaScript, from my understanding, the below are all same:

var carter2 = new String();
var carter2 = \'\';
var carter2 = \"\";

Which one is

5条回答
  •  终归单人心
    2021-02-04 08:54

    Definitely without the constructor function call.

    So with either single or double quotes (i.e. literal).

    Note, this kind of optimization (literal vs. constructor) I believe would only matter if you had hundreds or thousands of these statements though.

提交回复
热议问题