[ Web Proxy ]
URL:
Viewing: https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/String/String [Back]  [Original]

String() - JavaScript | MDN

MDN Web Docs

View in English Always switch to English

String()

20157

String() String String

js
new String(thing)
String(thing)

String() new

thing

String new String

String Symbol "Symbol(description)" description Symbol description

String

String String

String String

js
const a = new String("Hello world"); // a === "Hello world"  false
const b = String("Hello world"); // b === "Hello world"  true
a instanceof String; //  true
b instanceof String; //  false
typeof a; // "object"
typeof b; // "string"

String String

String() Symbol

String() Symbol

js
const sym = Symbol("");
`${sym}`; // TypeError: Cannot convert a Symbol value to a string
"" + sym; // TypeError: Cannot convert a Symbol value to a string
"".concat(sym); // TypeError: Cannot convert a Symbol value to a string
js
const sym = Symbol("");
String(sym); // "Symbol()"

ECMAScript 2027 LanguageSpecification
# sec-string-constructor


Web Proxy Viewer  |  New URL  |  Original Page