javascript - Default Parameters in Function Expressions -
default parameters in javscript function declerations can achieved simple assignment follows:
function foo(arg1 = 'default1', arg2 = 'default2') { ... }
but how can have default parameters function expressions, following not work in chrome v47:
var foo = function (arg1 = 'default1', arg2 = 'default2') { ... }
any pointers helpful.
you can't in javascript:
function foo(arg1 = 'default1', arg2 = 'default2') { ; }
see in console, gives syntax error. can this:
function foo(arg1, arg2) { if ("undefined" == typeof arg2) { arg2 = "default2"; } } var foo2 = function(arg1, arg2) { if ("undefined" == typeof arg2) { arg2 = "default2"; } }
Comments
Post a Comment