News for hackers. Stuff that matters.
Re:Default Parameters in JavaScript by STRML on Tuesday March 19, 2013 @11:39AM (#5401511)
You are correct, except this will not work in the significant case where any falsy value is passed ("", 0, null, NaN... I exclude undefined because that is the intended behavior) or with booleans.

A slightly more verbose, yet hardy syntax would go like this:

  function foo(arg1, arg2){
    arg1 = arg1 === undefined ? "foo" : arg1;
    arg2 = arg2 === undefined ? "bar" : arg2;
  }
This would catch the intended behavior, which is to fill a parameter when it is not supplied at all.
Re:Default Parameters in JavaScript by leeoniya on Tuesday March 19, 2013 @11:43AM (#5401540)
already was updating :)