Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

javascript Passing Function Value as Default Value

// using a function in default value expression

const sum = () => 15;

const calculate = function( x, y = x * sum() ) {
    return x + y;
}

const result = calculate(10);
console.log(result);            // 160
Source by developer.mozilla.org #
 
PREVIOUS NEXT
Tagged: #javascript #Passing #Function #Value #Default #Value
ADD COMMENT
Topic
Name
2+9 =