Differences between `undefined` and `null`
undefinedmeans a variable has not been declared, or has been declared but has not yet been assigned a value
nullis an assignment value that means “no value”
null. It is used by programmers to indicate that a
varhas no value.
undefinedis not valid in JSON while
nulltypeof is an
- Both are primitives
- Both are falsy
Boolean(undefined) // false,
Boolean(null) // false)
You can know if a variable is undefined
typeof variable === "undefined"
You can check if a variable is null
variable === null
The equality operator considers them equal, but the identity doesn’t
null == undefined // true null === undefined // false
MEET THE NEW JSTIPS BOOK You no longer need 10+ years of experience to get your dream job.
Use the 100 answers in this short book to boost your confidence and skills to ace the interviews at your favorite companies like Twitter, Google and Netflix.GET THE BOOK NOW
A short book with 100 answers designed to boost your knowledge and help you ace the technical interview within a few days.GET THE BOOK NOW