Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

15. Undefined > Conceptual Overview of the undefined Value

Conceptual Overview of the undefined Value

The undefined value is used by JavaScript in two slightly different ways.

The first way it’s used is to indicate that a declared variable (e.g., 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 (i.e., it has not even been named), and is not found in the prototype chain.

Below, I examine both usages of undefined by JavaScript.

Live Code

<!DOCTYPE html><html lang="en"><body><script>

var initializedVariable; // declare variable

console.log(initializedVariable); // logs undefined
console.log(typeof initializedVariable); / confirm that JavaScript returns undefined /

var foo = {};

console.log(foo.bar); // logs undefined, no bar property in foo object
console.log(typeof foo.bar); // confirm that JavaScript returns undefined

</script></body></html>

  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint