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"