Results 1 to 3 of 3

Thread: Small question about JavaScript operators in DWT code

  1. #1
    sdouglass is offline Intermediate Member
    Join Date
    Oct 2005
    Location
    Emeryville, CA US
    Posts
    22
    Rep Power
    9

    Default Small question about JavaScript operators in DWT code

    Hi! Like everybody else I'm very excited about your product and have been going over the code, mostly focusing on DWT at first. I've noticed a couple places where there's a JavaScript operator that I've not seen before. For example:

    AjxEventMgr.js:
    ...
    59: if (retVal === false)
    ...

    AjxVector.js:
    ...
    34: if (compress !== true)
    ...

    Are those equivalent to "==" and "!=" respectively? If not, how are they different? If so, why use them instead of "==" and "!="?

  2. #2
    KevinH's Avatar
    KevinH is offline Expert Member
    Join Date
    Aug 2005
    Location
    San Mateo, CA
    Posts
    4,789
    Rep Power
    18

    Default

    The === and !== are identity compares (ie check that things are identical without tye conversion) Some more detail below.






    From: http://www.crockford.com/javascript/lint.html



    The == and != operators do type coercion before comparing. This is bad because it causes '' == 0 to be true. This can mask type errors.

    When comparing to any of the following values, use the === or !== operators, which do not do type coercion.

    0 '' undefined null false true
    If you want the type coercion, then use the short form. Instead of
    (foo != 0)
    just say
    (foo)
    and instead of
    (foo == 0)
    say
    (!foo)

  3. #3
    JeffP is offline Junior Member
    Join Date
    Oct 2005
    Posts
    7
    Rep Power
    9

    Default

    Check out crockford.com and see his jslint utility to get used to using this operator in your own code. It only took me a couple of times of running my files thru it and I learned the crockford way..

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Postfix problem
    By jimbo in forum Administrators
    Replies: 46
    Last Post: 07-23-2007, 05:24 AM
  2. 3.0 to 4.5.3 Upgrade failed (mysql error)
    By dealt in forum Installation
    Replies: 35
    Last Post: 03-19-2007, 10:30 PM

Posting Permissions

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