I've read some questions here about this:
This is good
function(a, b) { a = (typeof a === 'undefined')? 'default_val' : a; b = (typeof b === 'undefined')? 'default_val' : b; }
This is somewhat troublesome (works for anything but boolean values)
function(a, b) { a = a || 'default_val'; b = b || 'default_val'; }
If you pass false it break the logic. So this should be marked as a bad habit
There were a few question, but I have never seen the answer to this (nobody answered directly to the question): is this (last method) good (does anyone sees any issues with it) ?
function(a = 'default_val', b = 'default_val') { // your code }
I have tested this 3th method but couldn't find any issues. I would like the last method. It is more cleaner and looks more like the structure of other languages.
Thanks
undefined
value into function. You must checkarguments.length
to do this work.