Javascript - Default value for argument

Posted . Visible to the public.
 function foo(a, b)
 {
   a = typeof a !== 'undefined' ? a : 42;
   b = typeof b !== 'undefined' ? b : 'default_b';
   ...
 }

And in coffeescript

foo = (container, liquid) ->
     container ?= "mug"
     liquid ?= "coffee"
Saul
Last edit
Posted by Saul to Saul (2012-12-27 05:17)