Evaluation of different data types in javascript
Objects
evaluate totrue
Undefined
evaluates tofalse
Null
evaluates tofalse
Booleans
evaluate to the value of the booleanNumbers
evaluate tofalse
if+0, -0, or NaN
, otherwisetrue
Strings
evaluate tofalse
if an empty string''
, otherwisetrue
Arrays
(whether empty or not ex:[] or [0]
) evaluates totrue
as array is an object
Prefer strict comparison over loose comparison
It is better to use strict comparison(===) over loose comparison(==) as the strict comparison does not do any coercion.
Coercion: Coercion in javascript refers to the process of automatic or implicit conversion of values from one data type to another.
Comments