Home » Check if JavaScript variable is NULL or Undefined

Check if JavaScript variable is NULL or Undefined

Check if JavaScript variable is NULL or Undefined, here we are learning about some very basic JavaScript functionality. At the time of Website development, we use NULL which is an assignment value.

javascript check if undefined
Check if JavaScript variable is NULL or Undefined

In JavaScript mostly we getting an error statement called undefined variable. Before we start with Check if JavaScript variable is NULL or Undefined.

First we learn about the difference between NULL or Undefined.

Difference between JavaScript NULL or JavaScript Undefined

In JavaScript, you can check the variable is Undefined or Null or empty string or has a value. Below are some points for clarifying the difference.

  1. In JavaScript Undefined means, the variable has declared but no value has assigned to it. Check below example:

Output:
Undefined
Undefined

2. JavaScript Null is an assignment value, which means a variable has no value. And null value has object type. See below example:

Output:
Null
Object

Before move forward, I have to clear that JavaScript NULL and JavaScript Undefined both are two distinct types.

  • Undefined is typing itself
  • A null is an Object

And

JavaScript typeof

Above we use JavaScript typeof in many places. So I want to clear you what is use of the JavaScript typeof operator. Also used for checking JavaScript array is empty or not.

The typeof operator returns a string indicating the type of variable

A Complete Lesson about Check if JavaScript variable is NULL or Undefined

Let’s talk about JavaScript check undefined or JavaScript empty array using some examples, here we start,

Using the above code you get the value “true” if the value is not,

  • Null
  • Undefined,
  • empty string
  • NaN
  • 0
  • False

You van also check like this,

Here are all the explanations above about Check if the JavaScript variable is NULL or Undefined. If you have any question please comment below.    

Also Check:

Know more about JavaScript: https://en.wikipedia.org/wiki/JavaScript  

Happy Coding…

Subscribe For Latest Updates

Sign up to best of PHP Code Solutions, informed analysis and opinions on what matters to you.
Invalid email address
We promise not to spam you. You can unsubscribe at any time.

1 thought on “Check if JavaScript variable is NULL or Undefined”

  1. Pingback: DOM | Document Object Model - PHPCODER.TECH

Leave a Reply

Your email address will not be published. Required fields are marked *