In the realm of JavaScript, default parameters are a powerful feature that enables you to set a predefined value for a function's parameters. This behavior, introduced in ECMAScript 6 (ES6), enhances code reusability and simplifies function define- tions by giving parameters an initial value.

The syntax for setting default values is straightforward. You simply assign a value to a parameter at the end of the parameter list, separated by a comma. If you call the function without providing a value for that parameter, it will use the default value. For example:

Defining Default Parameters
To define a default parameter in JavaScript, follow this syntax:

function greet(name = 'Guest') {
console.log(`Hello, ${name}!`);
}
Usage with Explicit and Implicit Parameter Values

You can use default parameters with explicit and implicit parameter values. An explicit value is provided when calling the function, while an implicit value is the default. For instance:
greet('Alice'); // Outputs: Hello, Alice!
greet(); // Outputs: Hello, Guest!

Default Parameters with Rest Parameters
It's also possible to use default parameters with rest parameters, which gather the remaining arguments into an array. Here's an example:
function sum(...numbers = []) {
let sum = numbers.reduce((total, num) => total + num, 0);
return sum;
}

sum(1, 2, 3); // Outputs: 6
sum(); // Outputs: 0




















Handling Default Parameters with 'use strict'
'use strict' is a directive that helps enforce best practices and prevents certain actions from being taken. When using default parameters with 'use strict', it's essential to be aware of hoisting behavior to avoid errors.
'use strict'; prevents you from using a variable that hasn't yet been declared, and this includes default parameters when they're hoisted. To avoid issues, make sure to declare variables before using them within strict mode. Here's an example:
Strict Mode and Default Parameters
Using default parameters in strict mode might lead to syntax errors due to hoisting. To avoid this, declare variables before using them. For example:
'use strict';
let name = 'Guest';
function greet(name = 'Guest') {
console.log(`Hello, ${name}!`);
}
In the end, default parameters provide immense flexibility and simplify JavaScript functions. They enable you to set sensible defaults that can be overridden when needed, making your code more intuitive and expressive.