Difference between null and undefined in JavaScript

What is the difference between null and undefined in JavaScript?
In JavaScript, undefined and null are two ways to represent "no value", but there are some interesting differences between the two. The distinction between undefined and null might be confusing to developers who are new to JavaScript since many programming languages represent missing values using null, and don't have a concept of "undefined". Basically their null value covers both. Null in JavaScript is a special object that can be assigned to a variable to represent "no value", but it's always the result of an explicit assignment in code. JavaScript will never initialize anything to null. Since it's an object, a typeof check on null will return "object", but the null object does not define any of the standard, built in properties, like toString, hasOwnProperty etc. Instead, think of it as an object that only offers a value of null - with no other behavior. Undefined is actually its own type in JavaScript. Any uninitialized variable will be of type "undefined", which means a typeof check will return "undefined" as the type. Undefined is also the default return value for any JavaScript method without an explicit return statement. It's unclear why JavaScript requires two "no value" representations, but as long as you are aware of their differences you might be able to benefit from their subtle differences in your code.
javascript
Check out more questions and answers here