let n = 0;
if (n) console.log("Truthy");
else console.log("Falsy"); // It print "Falsy"
Okay fine. But what wrong in the below code?
let n = new Number(0);
if (n) console.log("Truthy"); // it print "Truthy".
else console.log("Falsy");
The answer is very simple.
Let's check data type of the variables.
let n = 0;
console.log(typeof n); It print "number"
let n = new Number(0);
console.log(typeof n); It print "object"
Did you get your answer?
It is happening because of data type is differnt.
Thank You,
@sujitkar1195
Top comments (0)