This question has already been answered:
I was faced with such a situation that an empty line is not a true or a false
'' === true // false '' === false // false Is there any explanation for this?
This question has already been answered:
I was faced with such a situation that an empty line is not a true or a false
'' === true // false '' === false // false Is there any explanation for this?
A similar question was asked earlier and an answer has already been received. If the answers provided are not exhaustive, please ask a new question .
You use the comparison operator === , which also takes into account the data type of the operands. And since on the one hand you have a string variable, and on the other a boolean, the result will be negative. As for example, for 1 === true or 0 === false .
With the usual == comparison, you will get a different result due to the implicit type conversion.
console.log( '' === false) ; console.log( '' == false); In the usual comparison, false itself is calculated as false , 0 , "", '' , null , undefined , NaN . Everything else is true , like the one you mentioned.
Again, when comparing === equality of data types matters. This is the whole essence of this operator.
Source: https://ru.stackoverflow.com/questions/846951/
All Articles
if ([]) console.log(123) // 123andif ('') console.log(123) // ничего- Roma Boykoif- Grundy