Make your Confusion clear in JS

KUNTAL GHOSH
Nov 10, 2020

Truthy and Falsy

With type, every value has a boolean value called truthy or falsy value.

The following values are always falsy:

  • false
  • 0 (zero)
  • '' or "" (empty string)
  • null
  • undefined
  • NaN

Everything else is truthy. That includes:

  • '0' (a string containing a single zero)
  • 'false' (a string containing the text “false”)
  • [] (an empty array)
  • {} (an empty object)
  • function(){} (an “empty” function)

double equal (==) vs triple equal (===)

Loose Equality Comparisons With( ==)only compares 2 values not the types of the values

2==”2”// returns true

Strict Equality Comparisons With (===) compares 2 values with their type.

2==”2”// returns false

--

--