Small question about JavaScript operators in DWT code

Have a great idea for extending Zimbra? Share ideas, ask questions, contribute, and get feedback.
sdouglass
Posts: 22
Joined: Fri Sep 12, 2014 9:57 pm

Small question about JavaScript operators in DWT code

Postby sdouglass » Wed Oct 05, 2005 3:09 pm

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 "!="?


14319KevinH
Ambassador
Ambassador
Posts: 4558
Joined: Fri Sep 12, 2014 9:52 pm

Small question about JavaScript operators in DWT code

Postby 14319KevinH » Wed Oct 05, 2005 4:28 pm

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)
1340JeffP
Posts: 5
Joined: Fri Sep 12, 2014 9:57 pm

Small question about JavaScript operators in DWT code

Postby 1340JeffP » Thu Oct 06, 2005 11:43 pm

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..

Return to “Developers”

Who is online

Users browsing this forum: No registered users and 3 guests