Thursday, July 24, 2014

Difference between == and === (equals and triple equals)

The == and === equality operator are used in JavaScript

The === sign defines that value must be equal in type as well however == not.

Example :

0==false   // true
0===false  // false, because they are of a different type
1=="1"     // true, auto type coercion
1==="1"    // false, because they are of a different type

Code Snippet:

                    <script type="text/javascript">
                            function a() {
                               if (1 ==='1') {
                                           alert('true');
                                                   }
                              else {
                                           alert('False');
                                     }
                           }
                  </script>

No comments:

Post a Comment