Backbencher.dev

JS Daily 27 - Comparing String With String Object

Last updated on 17 Dec, 2020

What is the output of following code?

const a = "Backbencher";
const b = new String("Backbencher");
console.log(a === b);
----o----

The output is false.

a and b are not strictly equal. When === is used, if both type and value of operands are same, the return value is true. The type of a is string and that of b is object. Therefore a === b returns false.

--- ○ ---
Joby Joseph
Web Architect