Assigning undefined to a variable though is probably confusing, since it's a bit of a paradox (you've defined the variable as undefined) and it's not possible to distinguish that variable from either variables that don't exist or uninitialised variables. But if v isn't assigned anything, or gets another falsey value, x will get 10. While literally using the keyword undefined, boolean(undefined) works, trying that with an undefined variable doesn't work, and that is the whole point of doing the check for null or undefined.
stacyxregan of leak
The difference between null and undefined is
Javascript will never set anything to null, that's usually what we do
While we can set variables to undefined, we prefer null because it's not something that is ever done for us When you're debugging this means that anything set to null is of your own doing and not javascript. The biggest misconception in many of the answers here is that 'undefined' is a javascript keyword It's not a keyword at all, but a variable that (most of the time) happens to be undefined
So the only time somevar === undefined works is when the 'undefined' variable really hasn't been defined. Typeof foo !== 'undefined' window.foo !== undefined 'foo' in window the first two should be equivalent (as long as foo isn't shadowed by a local variable), whereas the last one will return true if the global varible is defined, but not initialized (or explicitly set to undefined). 390 the jquery core style guidelines suggest two different ways to check whether a variable is defined Typeof variable === undefined local variables
Object.prop === undefined why does jquery use one approach for global variables and another for locals and properties?
Undefined is a variable, not a constant, and can be assigned a value Because of this, one school of thought says the second path is safer, since you cannot be sure of the value of undefined.