Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • The difference between == and === in jQuery/Javascript?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 120
    Comment on it

    double (==) : This operator is used for checking equality, no strict comparison is done i.e this operator first converts the values to specific type then comparison is done and this conversion is done by the javascript interpreter. Type conversion also take place according to some rules:

    • The string is converted to a number value if a number and a string is compared.
    • For boolean,the boolean is converted to 1 if it is true and 0 if it is false.
    • When object is compared with a number or a string, the object is converted to its’ default value using (.valueof(), .toString()) methods. If these methods are missing a runtime error is thrown.
    • If an object is compared with another object, no type conversion is made. They are equal only if they refer the same object.

    triple (===) : This operator does strict comparison i.e not only values but their types need to be equal no conversion of types is done.

    Example:

    1 == true     // true 
    0 === false    // false, because they have different types (int, bool) 
    2 == "2"       // true 
    3 === "3"      // false, because they have different types (int, string) 
    null == undefined // true 
    null === undefined // false

     

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: