Is there is a standard function to check for null, undefined, or blank variables in JavaScript?

JavascriptObject Oriented ProgrammingFront End Technology

No there is not a standard function to check for null, undefined or blank values in JavaScript. However there is the concept of truthy and falsy values in Javascript.

Values that coerce to true in conditional statements are called truthy values. Those that resolve to false are called falsy.

According to ES specification, the following values will evaluate to false in a conditional context −

  • null
  • undefined
  • NaN
  • empty string ("")
  • 0
  • false

This means that none of the following if statements will get executed −

if (null)
if (undefined)
if (NaN)
if ("")
if (0)
if (false)
raja
Published on 19-Sep-2019 06:59:14
Advertisements