Difference between undefined and null in JS

I have been working in the industry from the long time and have noticed that due to the different language background , most of us , can not the harness the power of JS. In the article small article , I am trying to capture the concept that u need to have clarity to access your depth in JS.

Difference between undefined and null:

The difference of undefined and null can be compared to input box in a form question that does not applies to you and you have written NA. Let me explain using scenario analogy.

you asked a person supposed to be bachelor , to fill a form with one of the question

How may kids he/she have?

he/she has option to leave it blank or "NA" (Not applicable). But both of the answer has different meaning. If he/she has left "blank" , we may think, he might not have read the question or have missed it unintentionally , while if he/she has written it "NA", we can be sure the value is intentionally made "null"

var kid1;
console.log(kid1);

//print the value "undefined"


var kid2 = null;
consolelog(kid2);
//print the value "null"

To view or add a comment, sign in

More articles by abuzar hamza

  • Scope in JS

    Scope in JavaScript create a lot of confusion in programmer having C language family experience. All language has…

  • Difference between "==" and "===" in JS

    Most of us coming from different language background (Java, C , C++) have a confusion around "==" and "===" in…

Explore content categories