The other day I was thinking about how earlier last year, I was interviewing like crazy, and sometimes I had recruiter phone screens where I was quizzed on various JavaScript terms. As I think of some of the questions I’ve been asked previously, I plan to write articles focusing on these questions and answers.
NaN
NaN
means Not a number, and it denotes the value of an object is not a number. If you look at typeof NaN
it will return 'number'
since NaN
is a numeric data type that is undefined as a real number. NaN
can be returned if you do one of the following:
- Convert
undefined
into a number - Convert a non-numeric string into a number
- Divide zero by zero
- Divide infinity by infinity
- Operation where the result is not a real number
- Method/expression’s operand is or gets coerced to
NaN
null
null
means the object is empty. It’s an assignment value that can be assigned to a variable that has no value.
undefined
undefined
means that the object doesn’t have any value and is undefined. This happens when you declare a variable and don’t assign a value to it.