// First javaScript read the declaration function with name timesTwofunctiontimesTwo(num){returnnum*2}/* Second read the declaration variable with name result and see that
the value hold is a function timesTwo */constresult=timesTwo(8)/* Third javascript came back and replace the parameter num with the value 8 */functiontimesTwo(8){return8*2}functiontimesTwo(8){return8*2/* <= Fourth javascript run the block of code that result
16 */}/* Finally replace the expression (function) in the right side
of the variable with our result 16 that became the value of
our const result */constresult=16console.log(result)// then we log the result == 16
You might want to look into stack frames to understand what's really going on. This part is especially misleading to beginners:
/* Second read the declaration variable with name result and see that
the value hold is a function timesTwo */constresult=timesTwo(8)/* Third javascript came back and replace the parameter num with the value 8 */functiontimesTwo(8){return8*2}
I am sorry I will try to write it better in the mean times for you this is better :
function myFunction(a, b) {
return a * b;
}
myFunction(10, 2); // Function invocation, will return 20
//optional parameters (es6 only)
//allow to set optional parameters
function myFunction(a, b = 10) {
return a * b;
}
myFunction(1); // Function invocation, will return 10
myFunction(1,5); // Function invocation, will return 5
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
This is not how function invocations work:
You might want to look into stack frames to understand what's really going on. This part is especially misleading to beginners:
Thank you so much for your feedback 🙏
I am sorry I will try to write it better in the mean times for you this is better :
function myFunction(a, b) {
return a * b;
}
myFunction(10, 2); // Function invocation, will return 20
//optional parameters (es6 only)
//allow to set optional parameters
function myFunction(a, b = 10) {
return a * b;
}
myFunction(1); // Function invocation, will return 10
myFunction(1,5); // Function invocation, will return 5