javascript / beginner
Snippet
Setting Default Function Arguments
Default parameters allow named parameters to be initialized with default values if no value or undefined is passed. This is very useful in Next.js components for optional props that need a fallback value.
snippet.js
1
2
3
4
5
6
function getStatus(label = "Draft") {return "Status: " + label;}const result1 = getStatus("Published");const result2 = getStatus();
nextjs
Breakdown
1
label = "Draft"
Assigns 'Draft' to the label variable if the function is called without an argument.