Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

How Do Default Parameters Work in JavaScript?

// Default parameters let you assign a default value to a parameter when you define a function. For example:

function greeting(name, message = ”Hello”){
	console. log(`${messgae}  ${name}`)
}

greeting(‘John’); //output: Hello John

//you can also assign a new value to the default parameter 
//when you call the function

greeting(‘Doe’, ‘Hi’); //output: Hi Doe
Source by www.freecodecamp.org #
 
PREVIOUS NEXT
Tagged: #How #Do #Default #Parameters #Work
ADD COMMENT
Topic
Name
1+9 =