Friday 24 August 2018

===: Strict equality operator

By using '==' operator we can compare values of different types.

For example, to perform the comparison between a string, number Javascript  interpreter converts String to number.

"02" == 2 // It return true, since 02 is converted to number 2.

But in some cases, you want strict comparison, you can do this by using === operator.

"02" === 2 // It return false, since we are performing strict comparison using === operator.

strict.html
<!DOCTYPE html>

<html>

<head>
    <title>true and false</title>
</head>

<body>
    <script type="text/javascript">
        document.write("\"02\" == 2 : " + ("02" == 2) + "<br />");
        document.write("\"02\" === 2 : " + ("02" === 2) + "<br />");
    </script>
</body>

</html>



Previous                                                 Next                                                 Home

No comments:

Post a Comment