Is String a Primitive type or Object in Javascript?

前端 未结 4 1016
栀梦
栀梦 2020-11-30 04:55

Is String a Primitive type or Object in Javascript? Source says Undefined, Null, Boolean, Number and String are all primitive types in Javascript. But it says String is an O

4条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-30 05:14

    var a = "string"; 
    typeof a    // yields "string" 
    
    var a = new String('string'); 
    typeof a   // yields "object" 
    

提交回复
热议问题