Comparing the undefined and null Values - Javascript Language Basics

Javascript examples for Language Basics:Introduction

Introduction

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.

Demo Code

ResultView the demo in separate window

<!DOCTYPE HTML>
<html>
    <head>
        <title>Example</title>
    </head>
    <body>
        <script type="text/javascript">
            var myData = {//from  ww  w  .j a va2s.c  o  m
                name: "java2s.com",
                topic: "CSS",
            };
            document.writeln("Prop: " + myData.doesntexist);
        </script>
    </body>
</html>

null is used when you want to indicate you have assigned a value but that value is not a valid object, string, number, or boolean.


Related Tutorials