javascript - How does eval() treat a string object differently from a primitive string value? -


i reading in javascript book , talking difference between these 2 statements.

var s = "hello world"; // primitive string value var s = new string("hello world"); // string object 

i understand difference book mentioned (as little side note) eval() handle these differently didn't mention how.

i tried looking around google , couldn't find want example.com , started messing around it. couldn't see difference in way handled.

my question is: how eval() method treat these differently?

from mdn:

string primitives , string objects give different results when using eval. primitives passed eval treated source code; string objects treated other objects are, returning object. example:

s1 = "2 + 2";               // creates string primitive s2 = new string("2 + 2");   // creates string object console.log(eval(s1));      // returns number 4 console.log(eval(s2));      // returns string "2 + 2" 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -