Web Analytics Made Easy -
StatCounter difference between == and === operator - CodingForum

Announcement

Collapse
No announcement yet.

difference between == and === operator

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • difference between == and === operator

    the tital sais it all... i think
    http://www.bluephoenix.uni.cc/

  • #2
    == means equal to

    === means definately, most positively, no questions asked, equal to.

    Now for the proper meanings:

    Equal (==)
    Returns true if the operands are equal. If the two operands are not of the same type, JavaScript attempts to convert the operands to an appropriate type for the comparison
    examples
    3 == var1
    "3" == var1
    3 == '3'

    Strict equal (===)
    Returns true if the operands are equal and of the same type.
    example
    3 === var1

    in the examples, var1 has the value of 3
    Last edited by Nightfire; Feb 18, 2004, 09:27 PM.

    Comment


    • #3
      Originally posted by Nightfire
      === means definately, most positively, no questions asked, equal to.
      I believe the phrase you're looking for is "strict equality"
      "Why bother with accessibility? ... Because deep down you know that the web is attractive to people who aren't exactly like you." - Joe Clark

      Comment


      • #4
        oh ok i get it but when would u need a === operator?
        http://www.bluephoenix.uni.cc/

        Comment


        • #5
          Originally posted by JAVAEOC
          oh ok i get it but when would u need a === operator?
          When, as already implied, you want strict equality. The variables on each side of the operator must have equal values and of the same data type. For example, with your normal equality operator, this would return true:
          Code:
          '3' == 3;
          This is because it merely checks to see if the two values are equal to each other — it doesn't care about the data type. However, when you use the strict equality operator in the same situation:
          Code:
          '3' === 3;
          It will return false simply because the first is of the string data type, and the second is of the number data type.
          Moderator @ WebDeveloper.com
          Mentor @ WebXpertz.net

          Comment


          • #6
            cool
            http://www.bluephoenix.uni.cc/

            Comment

            Working...
            X