Default Values
Default values are values that are taken up by the parameters of a function when no corresponding argument is passed into the function call.
We can assign default values to parameters using the syntax:
function funcName(parameter1 = value1, parameter2 = value2, β¦) {
// your code here β¦
}
Example:
12345function sum(a = 5, b = 10) { return a + b; } console.log(sum()); // Output: 15
1. What happens if a function parameter has a default value and no argument is passed for it in the function call?
2. What will be the output of the following code?
3. What will be the output of the following code?
Thanks for your feedback!
Ask AI
Ask AI
Ask anything or try one of the suggested questions to begin our chat
Can you explain why using default values is better than using an if statement inside the function?
What happens if I pass only one argument to a function with multiple default parameters?
Can you show more examples of using default values with different data types?
Awesome!
Completion rate improved to 1.33
Default Values
Swipe to show menu
Default values are values that are taken up by the parameters of a function when no corresponding argument is passed into the function call.
We can assign default values to parameters using the syntax:
function funcName(parameter1 = value1, parameter2 = value2, β¦) {
// your code here β¦
}
Example:
12345function sum(a = 5, b = 10) { return a + b; } console.log(sum()); // Output: 15
1. What happens if a function parameter has a default value and no argument is passed for it in the function call?
2. What will be the output of the following code?
3. What will be the output of the following code?
Thanks for your feedback!