|
Answer» Both null and undefined REPRESENTS empty values. Let’s understand them first and then we will SEE what is the difference. undefined To understand “undefined” we have to understand what is declaration and definition of VARIABLES. When we declare a VARIABLE as in below diagram by “var value”, the compiler makes space for a variable “value”. The definition means that we assign a value to the variable and it’s allocated in that space. You can also do these two together by var value = 42; So, every language have a way of handling the value of a variable between function declaration and definition. In JavaScript that is HANDLED by type “undefined”. The type undefined is a primitive type which have only one value possible i.e. undefined. null It is also similar to “undefined” and is a primitive type. It also have only one possible value i.e. null. It is also used to represent empty values, but is generally assigned by the users. var a;
console.log(a); //undefined
a = null;
console.log(a); //null
|