3

Possible Duplicate:
Javascript === vs == : Does it matter which “equal” operator I use?

Are != and !== are respectively the same as == and ===?

Community
  • 1
  • 1
ilyo
  • 35,851
  • 46
  • 106
  • 159

4 Answers4

15

!== and === are strict comparison, and == / != are loose comparison. It's best to use strict comparison.

wanovak
  • 6,117
  • 25
  • 32
  • Well, i think loose comparisons are useful. – Pwnna Jul 14 '11 at 12:37
  • I didn't say they weren't, but if you're used to using strict comparison and only use loose when it's useful to, you're going to run into a lot less bugs (generally.) – wanovak Jul 14 '11 at 12:39
  • That's not a sufficient answer. Iit is better, because ... ? You are running into a lot less bugs, because ...? – JensG Feb 08 '19 at 09:34
6

true == 1 gives you true

true === 1 gives you false

Reason is that == compares only the value (so that 1, '1' is considered as true)

=== compares the value and the type.

Same thing in PHP.

Pwnna
  • 9,178
  • 21
  • 65
  • 91
4

== compares the value of object while === compares the object value and type.

hungryMind
  • 6,931
  • 4
  • 29
  • 45
2

yes it is.

<script>   

    var str = '1234';
    var int = parseInt('1234');

    if (int !== str)
    {
       alert('returns true and alerts');
    }

    if (int === str)
    {
       alert('returns false');
    }
</script>

http://sandbox.phpcode.eu/g/c801e.php

genesis
  • 50,477
  • 20
  • 96
  • 125