def foo(var="default"):
print(var)
$ foo()
default
$ foo("not default")
not default
function bar(var="default") {
console.log(var);
}
$ foo()
function bar(var="default")
SyntaxError: Unexpected token =
at Module._compile (module.js:439:25)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (/usr/local/src/test.js:4:16)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
@joshfinnie: The general answer is "it depends on what you need" and "it ain't pretty like Python".
When you just need to test for a non-falsy variable, I'd do:
If you want to actually check actually arguments (vs. a specified
undefined), I'd do:Once you get in to optional parameters and re-ordering, then you have a lot of
argumentsslicing and inference to do ;)