Free Trial

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

Share this Page URL
Help

CHAPTER 4: JavaScript Primer > Comparing undefined and null Values - Pg. 123

CHAPTER 4 JAVASCRIPT PRIMER Comparing undefined and null Values JavaScript defines a couple of special values that you need to be careful with when you compare them: undefined and null. The undefined value is returned when you read a variable that hasn't had a value assigned to it or try to read an object property that doesn't exist. Listing 4-34 shows how undefined is used in JavaScript. Listing 4-34. The undefined Special Value <!DOCTYPE HTML> <html> <head> <title>Example</title> <script type="text/javascript"> var myData = { name: "Adam", weather: "sunny", }; console.log("Prop: " + myData.doesntexist); </script> </head> <body> This is a simple example </body> </html>