default. wooden letters on the office desk, informative and communication background

Default Parameters

When writing functions, we might have times when we have argument sent and other times when no arguments are sent to the function. In the cases where no arguments are sent, we might want to have default parameter values.

let getName = (animalName = ‘Bongo’) => {
     return animalName;
}
console.log(getName()); 

In this case, “Bongo” prints out because we did not send any arguments. If we change our log statement…

console.log(getName(‘George’)); 

The output will now be “George”.

Share this post

Share on facebook
Share on google
Share on twitter
Share on linkedin
Share on pinterest
Share on print
Share on email
Skip to content