Return to Snippet

Revision: 4365
at December 2, 2007 06:19 by 1man

Initial Code
function optionalArguments(a, /*optional*/b){
	if(!b){b = []};//If b isn't set, create an empty array
	//OR shorthand for this
	b = b || [];
	 * The OR operator looks to see if b is true, if it is it skips
	 * creating the Array. If b is false it creates the array. Not
	 * very readable.

Initial URL

Initial Description
Simple way of allowing functions to take optional arguments. Always place the optional arguments last, so you don't have to explicitly pass an argument as "undefined".

Initial Title
Optional Function Arguments

Initial Tags
javascript, function

Initial Language