Creating Code For Simplicity but Logic For Need
Comparing Falsy and Truthy values
The need for learning these values is because of its use in comparison. The comparison is where these values creates many troubles. Misinterpretation of any value may lead to the wrong action in a script. Therefore it is necessary to check for truthy and falsy values correctly.
The Falsy values 0, “” (empty string) and false are equal to each other and comparison among them results in a true value.
Null and undefined are equal to themselves.
To avoid the logical error in a script you can use triple equal (===) or triple not equal(!==). Unlike a double equal (==) that uses a value for the equality check, triple equal (===) checks on the basis of value and type.
From the preceding article I can suggest that you always use a triple equal since it is difficult to memorize the rules of double equal and truthy falsy comparison results. Thanks for reading this article. Don’t forget to share and comment.