Small question about JavaScript operators in DWT code

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

Small question about JavaScript operators in DWT code

Post by sdouglass »

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

Post by 14319KevinH »

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

Post by 1340JeffP »

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