Default Parameters
What will be logged? function display(a, b = 5, c = b) { console.log(a, b, c); } display(1, undefined, 3);
The code will log `1, 5, 3`. When the function is called with `display(1, undefined, 3)`, the parameter `a` gets the value 1. The second argument is `undefined`, which triggers the default value for parameter `b`, making it 5. The third argument is 3, which is explicitly provided for parameter `c`, overriding its default value. This example illustrates how default parameters interact with explicitly passed values, including `undefined`. It's important to understand that default values only kick in when the parameter receives `undefined` or when no argument is provided. In this case, even though `b`'s default value is used (because `undefined` was passed), `c` doesn't use its default (which would have been the value of `b`) because an explicit value (3) was provided for it. This demonstrates the flexibility of default parameters in handling various calling patterns.