To test to ensure that the values and the types are the same, you need to use the identity operator ===. - Javascript Language Basics

Javascript examples for Language Basics:Introduction

Description

To test to ensure that the values and the types are the same, you need to use the identity operator ===.

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 .  ja  v  a 2 s  . c  o  m*/
           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