On Thu, May 14, 2015 at 9:40 AM, Gijs Kruitbosch <gijskruitbo...@gmail.com> wrote: > Do you think the people that wrote the style guide (not me, so I'm not > trying to be defensive over the document, to be clear) did not understand > what they wrote? :-)
No, but I do think that they were wrong. >> Crockford offers plenty of >> reasons in his book. > > > I've not read Crockford's book and have no plans to, but there are plenty of > reasons against, too. :-) Do you want me to send you a copy? > then that does not mean I don't care or don't know - I *know* that > ary.length is a number, and there's no reason to bother with writing "===". That just says that you are too lazy to hit the key one more time. And that you don't care to signal to others that you know this. > Likewise, if I know an argument to a function is either not present or a > non-empty string, and I do: > > if (arg) { > dosomethingwitharg(arg); > } I'm actually perfectly fine with this form. Including something in a conditional statement is pretty damned explicit as far as I'm concerned. It's at least as clear as if (!!arg) and easier to read. (I have a personal bugbear against the falsy-ness of the empty string, but I can concede that point.) >> I've never seen case >> where an explicit check is not possible, and does not help make code >> clearer. > > I disagree. new String() is my most hated example ("foo" == new > String("foo")) but ("foo" !== new String("foo")), but also in places where > we use implicit truthy/falsy checks, the shorthand 'if (foo)' and/or 'if > (!foo)' is much more useful, clear and concise than trying to check for all > the ways in which foo could be falsy/truthy (and inevitably forgetting > something silly like NaN or types from other windows when using instanceof > or ...). I have no idea what you are talking about. I have never had cause to use new String() anywhere. .toString() maybe. x = "foo"; if (x === "foo") { ... } // is fine _______________________________________________ dev-platform mailing list dev-platform@lists.mozilla.org https://lists.mozilla.org/listinfo/dev-platform