User Tools

Site Tools


Java Script Falsy and Truthy Values

Falsy values

A falsy value is a value considered false if it's encountered in a boolean context.

These are the falsy values:

  1. false: The keyword false itself is obviously considered falsy.
  2. 0, -0, 0n, -0n: The number zero (including its negative counterpart and big int) is considered falsy.
  3. “”, '' and `` (empty strings): An empty string is considered falsy.
  4. null: The null keyword is considered falsy.
  5. undefined: The undefined keyword is also falsy.
  6. NaN: “Not a Number” is considered falsy.

Truthy values

Everything that is not a falsy value is a truthy value.

This includes:

  • '0'
  • 'false'
  • []
  • {}
  • function () {}
java-script/falsy-truthy-values.txt · Last modified: 2023/08/09 20:47 by odefta