A
String
object can always be converted to its primitive counterpart with the
valueOf()
method.
If you want to change selection, open document below and click on "Move attachment"
String - JavaScript | MDNeval(s2)); // returns the string "2 + 2"
For these reasons, code may break when it encounters String objects when it expects a primitive string instead, although generally authors need not worry about the distinction.
<span>A String object can always be converted to its primitive counterpart with the valueOf() method.
console.log(eval(s2.valueOf())); // returns the number 4
Note: For another possible approach to strings in JavaScript, please read the article about StringView — a C-like repre Summary
status | not read | | reprioritisations | |
---|
last reprioritisation on | | | suggested re-reading day | |
---|
started reading on | | | finished reading on | |
---|
Details