Search code snippets, questions, articles...

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]);
Best JSON Validator, JSON Tree Viewer, JSON Beautifier at same place. Check how cool is the tool

Live Demo

Was this helpful?