O'Reilly logo

Scripting in Java: Integrating with Groovy and JavaScript by Kishori Sharan

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

var str = "Hello";// Assigns a wrapper for str to p1 because str is a primitive typevar p1 = new Object(str);print("p1.valueOf() is", p1.valueOf());print("typeof p1 is", typeof p1);print("p1.valueOf() === str is", p1.valueOf() === str);var msg = new String("Hello");// Assigns the reference of msg to p2. new Object(msg) returns// the reference of msg because msg is an object.var p2 = new Object(msg);print("p2 === msg is", p2 === msg);print("p2.valueOf() is", p2.valueOf());print("typeof p2 is", typeof p2);print("p2.valueOf() === msg is", p2.valueOf() === msg);
p1.valueOf() is Hellotypeof p1 is objectp1.valueOf() === str is truep2 === msg is truep2.valueOf() is Hellotypeof p2 is objectp2.valueOf() === msg is false

Table 4-11 contains the list ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required