I have tried 2 conditions in JavaScript and output:
if(""){console.log("Called")} //No Output
if("_"){console.log("Called")} //Output: Called
What could be the possible reason for this?
I have tried 2 conditions in JavaScript and output:
if(""){console.log("Called")} //No Output
if("_"){console.log("Called")} //Output: Called
What could be the possible reason for this?
The empty string is considered as a 'falsy' value, and so it's equivalent to doing:
if(false){console.log("Called")}
The empty string is equal to False if you cast it to Boolean (Type Conversion).
console.log(Boolean("")) //output: false
console.log(Boolean("somestring")) //output: true