Difference between NULL and Undefined in Javascript
Null: It is the intentional absence of the value. It is one of the primitive values of JavaScript.
Undefined: When we declares a variable but doesn't assign any value to it. It means the value does not exist in the compiler. It is the global object.
Below are some difference between NULL and Undefined in JavaScript:
1. NULL is assignment value. Means we can assign NULL as a value to a variable. But Undefined is not an assignment value.
Example:
let firstName = NULL; // No error
let firstName = undefined; // Throw error
2. Type of NULL is "Object" but type of undefined is "Undefined".
Example:
console.log(typeof null) // Output: object
console.log(typeof undefined) // Output: undefined
null == undefined // true
null === undefined // false
Comments
Post a Comment