There are a lot of ways, but this is my preferred method - it lets you pass in anything you want, including false or null. (typeof null == "object")
function foo(a, b) { a = typeof a !== 'undefined' ? a : 42; b = typeof b !== 'undefined' ? b : 'default_b'; ... }Read full article from Set a default parameter value for a JavaScript function - Stack Overflow
No comments:
Post a Comment