null, undefined and NaN

null

null represents “no value,” meaning “nothing,” not even an empty string or zero.

It’s used as a placeholder in a variable to let you know there’s nothing useful in there.

It’s a reference to nothing.

When a variable is assigned null, it does not contain any valid data type.

It can be used to initialise a variable so that it does not produce errors or to clear the value of a variable, so that there is no longer any data associated with that variable, and the memory used by it is freed by the garbage collector

undefined

A variable that has been declared, but given no initial value, contains the value undefined and will produce a runtime error if you try to use it.

The word undefined is not a keyword in JavaScript.

The difference between null and undefined is subtle.

If nothing (not even null) has ever been stored in a variable, then it’s undefined, but for convenience, much of the time it acts as if it had a null value.

If compared with the == equality operators, null and undefined are equal, but if compared with the === identity operator, they are not identical.

NaN

NaN means ‘Not a Number’ and is the result of a mathematical operation that makes no sense.

Advertisements

About metawrap

CTO Massive Interactive. Ex Computer Whiz Kid - Now Grumpy Old Guru.
This entry was posted in Uncategorized. Bookmark the permalink.

One Response to null, undefined and NaN

  1. Phil H says:

    Damn dude, you do think too much about this kinda stuff don’t you. 🙂

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s