Differentiating Between null and undefined - Javascript Language Basics

Javascript examples for Language Basics:Introduction

Introduction

The following code shows the Equality and Identity Comparisons for null and undefined Values.

Demo Code

ResultView the demo in separate window

<!DOCTYPE HTML>
<html>
    <head>
        <title>Example</title>
    </head>
    <body>
        <script type="text/javascript">

            var firstVal = null;/*  www. j  a  va  2s  .co m*/
            var secondVal;

            var equality = firstVal == secondVal;
            var identity = firstVal === secondVal;

            document.writeln("Equality: " + equality);
            document.writeln("Identity: " + identity);

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

Related Tutorials