Re: JSLint and JavaScript: The Good Parts.



On Sat, 2010-03-13 at 13:21 +1100, Lex Hider wrote:

> However, this one (== vs ===) does seem to be a very worthwhile change
> to the style guide to consider.
> Wouldn't it be clearer if code depending on (0 != null but undefined
> ==null) be made explicit?

I've (in the past) read what Crockford has to say on the issue, and
didn't find it convincing.

Yes, the coercion behavior of the standard '==' is surprising
at times (strings to numbers in particular), but that only happens
of you are comparing items that are in fact of different types. Which is
generally not good programming practice.

But if you use '===', then you have to have an accurate mental model of
where javascript uses 'undefined' and where it uses 'null', and that's
hard and obscure.

And also, you make the code look strange and intimidating.

So, my rule is that you should only use === and !== if it actually makes
a difference and you should try to avoid situations where it actually
makes a difference.

- Owen





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]