Can any one? | SoloLearn: Learn to code for FREE!


Can any one?

What is the output of this code? if ("String" == ["String"] ) { const str = new String ("String"); console.log(str == String); } else console.log("exit");

3/31/2020 3:11:51 AM

Keerthana RÊDD¥

1 Answer

New Answer


Type Coercion When array ["String"] is compared with a string "String" with loose comparison operator, its toString function is invoked, so we are comparing "String" with "String", so the if condition is true. Then, in the if code block, str is a string object "String" constructed with the String constructor, and String without quotation mark is a reserved word, pointing to the constructor function. When we compare an oject with a function, it returns false. So the printed result is false.