Default Parameters A JavaScript function can have default parameter values. Using default function parameters, you can initialize formal parameters with default values. If you do not initialize a parameter with some value, then the default value of the parameter is undefined. Example 1 Without passing argument value function Hello(name) { console.log('Value Of Name parameter = ' + name ) } Hello(); Output Value Of Name parameter = undefined Example 2 passing argument value function Hello(name) { console.log('Value Of Name parameter = ' + name ) } Hello("Hello"); Output Value Of Name parameter = Hello Example 1 With Set Parameters Default vlaue // Add Name parameter default value is 'Hello World' check below function Hello( name='Hello World' ) { console.log('Value Of Name parameter = ' + name ) } // Calling without passing arguments show the default value Hello(); Output Value Of Name ...
Comments
Post a Comment