10 biggest JS pitfalls
waldron.rick at gmail.com
Sun Jan 6 17:41:09 PST 2013
On Sunday, January 6, 2013, Axel Rauschmayer wrote:
> > Exactly Brendan, I could not agree more and this is my No. 1 pitfall
> about JS: developers often not doing real work complaining about stuff that
> developers doing real work don't even care about or never ever had to worry
> I don’t follow. Who are these people not doing “real work”? And I don’t
> think discussing the language qualifies as complaining.
> > In any case they can learn and understand the feature/problem using the
> feature when needed, avoiding its weakness when necessary.
> > About falsy and truthy, null and undefined, who cares ... seriously, and
> to be honest, that's not a pitfall, is rather a feature when needed as it
> is for all other scripting languages as long as you know what you are doing
> ... and no programming language will save you if you don't know what you
> are doing and it's your duty, as developer, to understand the language you
> are using if that's your job.
> “Warts” is probably a better term than “pitfalls”.
> > Again, about falsy ... if I see a glass empty, it does not mean I used a
> microscope to understand no water is left in the whole glass surface ... I
> just consider that empty and I add water on top.
> > Engineers have the tendency to over complicate even simple tasks as the
> one I've just described ... what is the benefit? What is the result? That
> the day falsy values in JS will disappear libraries authors will implement
> an isFalsy(value) function/method and use it 90% of the time regretting the
> trick with == disappeared ... isn't it ;-)
> What is the trick with ==? Note that == does not respect truthiness or
> > 2 == true
> > 2 == false
> > '2' == true
> > '2' == false
None of these (above) abstract comparison operations represents "truthy" or
0 == false;
188.8.131.52 converts to 0==0
"" == false;
184.108.40.206 converts to ""==0
220.127.116.11 converts to 0==0
1 == true;
18.104.22.168 converts to 1==1
"" becomes +0 per 9.3.1
+0 becomes false per 9.2
true becomes 1 per 9.3 table 12
The unary logical NOT ! also converts with ToBoolean.
2==true is just the number two compared with the Boolean true, which aren't
equal in value or type and have no criteria for conversion.
> Dr. Axel Rauschmayer
> axel at rauschma.de
> home: rauschma.de
> twitter: twitter.com/rauschma
> blog: 2ality.com
> es-discuss mailing list
> es-discuss at mozilla.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the es-discuss