News for hackers. Stuff that matters.
Re:Fun.js – Just a sketch by dweinus on Thursday June 06, 2013 @06:05PM (#5835463)
Sorry to nitpick, but I got hung up right at the beginning with his "truthy" function.

It returns true on values such as NaN, zero, or an empty string. I don't think I'm alone in considering those to be "falsy" values, for example:

http://www.sitepoint.com/javascript-truthy-falsy/

Re:Fun.js – Just a sketch by fogus on Thursday June 06, 2013 @06:16PM (#5835521)
Technically the are JS falsey, but I choose not to treat them that way. I rarely want to treat the result of a calculation as a boolean condition. However, I often want to know if a calculation isNaN or isEmpty. Just because something is falsey doesn't mean it should be treated that way universally.
Re:Fun.js – Just a sketch by dweinus on Thursday June 06, 2013 @06:27PM (#5835580)
Right on, I get that, but truthy(NaN) and truthy(5) both return true, so you still don't know if the calculation isNaN.

Btw, I should have said first: I love the article in general and it's great to see these techniques becoming more mainstream in javascript. Thank you!

Re:Fun.js – Just a sketch by fogus on Thursday June 06, 2013 @07:24PM (#5835944)
I would probably structure the problem like this:

    var ans = someCalculation(x,y);
    
    if (truthy(ans) && !isNaN(ans))
      //do something
    else
      //do something else
The point being I like to dispatch conditions on boolean results of certain properties of my results rather than the result directly. It helps me to keep my sanity.

Thanks for the kind words BTW. :-)

Re:Fun.js – Just a sketch by kivikakk on Thursday June 06, 2013 @06:28PM (#5835586)
It's probably as common to have them falsy as truthy; notably, they're truthy in Ruby.