Evaluation of different data types in javascript
Objectsevaluate totrueUndefinedevaluates tofalseNullevaluates tofalseBooleansevaluate to the value of the booleanNumbersevaluate tofalseif+0, -0, or NaN, otherwisetrueStringsevaluate tofalseif an empty string'', otherwisetrueArrays(whether empty or not ex:[] or [0]) evaluates totrueas 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