Difference between string primitive and string wrapper object in Javascript [duplicate]
问题 This question already has answers here : What's the point of new String(“x”) in JavaScript? (8 answers) Closed 4 years ago . I'm very confused about what the wrapper objects for primitives. For example, a string primitive and a string created with the string wrapper object. var a = "aaaa"; var b = new String("bbbb"); console.log(a.toUpperCase()); // AAAA console.log(b.toUpperCase()); // BBBB console.log(typeof a); // string console.log(typeof b); // object Both give access to String.prototype