For these reasons, code may break when it encounters String
objects when it expects a primitive string instead,
If you want to change selection, open document below and click on "Move attachment"
String - JavaScript | MDNar s1 = '2 + 2'; // creates a string primitive
var s2 = new String('2 + 2'); // creates a String object
console.log(eval(s1)); // returns the number 4
console.log(eval(s2)); // returns the string "2 + 2"
<span>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.
A String object can always be converted to its primitive counterpart with the valueOf() method.
console.log(ev Summary
status | not read | | reprioritisations | |
---|
last reprioritisation on | | | suggested re-reading day | |
---|
started reading on | | | finished reading on | |
---|
Details