www.webdeveloper.com
Results 1 to 3 of 3

Thread: What does === mean?

  1. #1
    Join Date
    Sep 2007
    Posts
    5

    What does === mean?

    Hi.

    This is a real newbie question, I think, but I can't seem to find the answer.

    I am looking at some javascript code and it uses a triple equal operator. Here's a sample of it:

    Code:
    if (b) return b !== !0 && a.getAttribute("classid") === b
    What does that === operator do? I find references to = and == (assign and compare respectively) but I cannot find any reference to ===.

    Thanks in advance...

  2. #2
    Join Date
    May 2012
    Posts
    29
    === is an exact match which considers type.

    Because JavaScript does type coercion when using == the following statement is true

    Code:
    "2" == 2;  // true
    If you want the above statement not to be true use the ===

    Code:
    "2" === 2;  // false
    but

    Code:
    2===2;  // true
    Some professional web developers such as Doug Crockford recommend using === as much as possible instead of ==.

  3. #3
    Join Date
    Aug 2010
    Location
    San Diego
    Posts
    242
    I hardly ever use "==" for comparisons, instead use "===". What this means is I simply avoid situations where I would want to know if
    Code:
    "2" == 2 // true
    new String == 0 // true
    "" == false // true
    "" == 0 // true
    "" == false // true
    new String == false // true
    0 == false // true
    
    /*note the logical inconsistency of the following 3 lines*/
    "0" == false // true
    new String == false // true
    new String == "0" // false

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles