This Cyber Monday Tuts+ courses will be reduced to just $3 (usually $15). Don't miss out.
The first way it's used is to indicate that a declared variable (
var foo) has no assigned value. The second way it's used is to indicate that an object property you're trying to access is not defined (it has not even been named), and is not found in the prototype chain.
In the following sample, I examine both usages of
undefined. You should never find yourself setting a value to
undefined, as in
foo = undefined. Instead,
null should be used if you are specifying that a property or variable value is not available.
undefined declared in the global scope. Because the variable is declared and not assigned a value, the undefined variable is set to
<!DOCTYPE html><html lang="en"><body><script> // Confirm that undefined is a property of the global scope. console.log(undefined in this); // Logs true. </script></body></html>
Having a good understanding of the