Using the Equality and Identity Operators - Javascript Language Basics

Javascript examples for Language Basics:Introduction

Introduction

The equality operators attempt to coerce operands to the same type in order to assess equality.

The following code shows the equality operator in action.

Demo Code

ResultView the demo in separate window

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

           var firstVal = 5;//from   w  w  w .  j  a v a  2s . c om
           var secondVal = "5";

            if (firstVal == secondVal) {
                document.writeln("They are the same");
            } else {
                document.writeln("They are NOT the same");
            }
        </script>
    </body>
</html>

Related Tutorials