JavaScript: Difference Between String() vs new String()

By Xah Lee. Date: . Last updated: .

both converts any value to a string. one returns a string primitive, the other returns a string object.

const xx = "abc";
const yy = String(xx);

console.log(yy === xx);
console.log(typeof yy === "string");
const xx = "abc";
const yy = new String(xx);

console.log(typeof yy === "object");
console.log(Array.isArray(yy) === false);

back to JavaScript: String Constructor

JavaScript String

JavaScript in Depth