How to set a default parameter value for a JavaScript function?

JavascriptWeb DevelopmentFront End Technology

This came to handle function parameters with ease. You can easily set default parameters to allow initialization of formal parameters with default values. This is possible only if no value or undefined is passed. Let’s see an example

Live Demo

         // default is set to 1
         function inc(val1, inc = 1) {
            return val1 + inc;
Updated on 13-Sep-2019 12:43:10