javascript
Assign default values to function parameters in Javascript
You can assign default values to function parameters in Javascript. If you have assigned a default value to a parameter , you don't need to pass it as a parameter if you do not want to change the value.
const func = (arr, arg2 = 0, len = arr.length) => { // Here arg2 and len are parametes with default values.
return len;
}
const result = func([10, 30, 40, 50, 60]);
console.log(result);
Live Demo
Was this helpful?
Similar Posts
- Javascript ES6 Rest Parameters
- Assign min and max values to y-axis in Chart.js
- Navigate to Page with parameters
- Pass a function as parameter of another function in Javascript
- Assign items of arrays to multiple variable when creating it (Array Destructuring) Javascript(ES6)
- Assign fixed width to the columns of bar chart in Chart.js
- Assign a fixed height to chart in Chart.js