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 ...

Get Scripting in Java: Integrating with Groovy and JavaScript now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.