JavaScript : ‘null’ vs ‘undefined’

lost here

Difference between ‘null’ and ‘undefined’?

Many of you still think that in JavaScript, null and undefined are same, but answer is:

null !== undefined

1. null

The value null represents the intentional absence of any object value. It is one of JavaScript’s primitive values and is treated as falsy for boolean operations.

If I say null is an object? Would you believe me? Watch below gif

gif demonstrating null

It was surprising to me also, but this the wonderful JavaScript. We should really understand the working of JavaScript.

null means empty and can be assigned and which means nothing.

2. undefined

The global undefined property represents the primitive value undefined. It is one of JavaScript’s primitive types., what you are thinking is not like that ? undefined is not an object like null

gif demonstrating undefined

undefined means a variable which was declared but not yet been assigned any value.

example for undefined

undefined is of type undefined



undefined is something which is not defined and is of undefined type

null is empty and having no value and is of object type

There are many thing which is still to explore by us in JavaScript. JavaScript really very deep and powerful. Invest your time to learn JavaScript by considering example for each concept you learn.

4 thoughts on “JavaScript : ‘null’ vs ‘undefined’”

Leave a Reply

Related Post

%d bloggers like this: