Possible Duplicates:
Javascript: undefined !== undefined?
What is the best way to compare a value against 'undefined'?
I’ve played around with the console and got some strange results when checking undefined,
when I do var a; a‘s type and value become "undefined" right?
So why a===undefined is true and a=="undefined" or a==="undefined" are false?
and, would typeof a == "undefined" be the best practice like in other languages?
Unrelated – how do I markup code in a question from iPhone?
When doing a==”undefined” or a===”undefined” you’re comparing the value of a with a string which contains the characters u, n, d, e, f, i, n, e, d.
So your expression boils down to undefined==”somestring”, which is obviously false.
typeof returns a string, so in this case comparing it to a string works.