please refer to this.
The
'return'
keyword is powerful because it allows functions to produce an'output'
. We can then save the*output*
to a*variable*
for later use."
It says there that the
'return'
keyword is capable of producing an'output'
that can be saved into a'variable'
for later use. It didn’t tell us how to set an identifier(Variable name
) to that'variable'
.that was created by the'return'
keyword.
function monitorCount(rows,columns) {
return rows*columns
}
const numOfMonitors = monitorCount(5,4);
console.log(numOfMonitors);
I believe that the purpose of the code above is to show us how we can set an
identifier
to the variable that was created by thereturn
keyword.
please refer to this. " The return keyword is powerful because it allows functions to produce an output. We can then save the output to a variable for later use."
It says there that the ‘return’ keyword is capable of producing an output that can be saved into a variable for later use. It doesn’t say how we are going to set an identifier/variable-name to that variable.
function monitorCount(rows,columns) {
return rows*columns
}
const numOfMonitors = monitorCount(5,4);
console.log(numOfMonitors);
I believe that the purpose of the code above is to show us how we can set an identifier to the variable that was created by the return keyword.
by doing this —>
let numOfMonitors = monitorCount(5,4)
we are basically saying that theoutput
of thereturn
keyword will be saved inside the variable callednumOfMonitors
. We can also interpret it as saying that thevariable
callednumOfMonitors
will have the same value as the value ofreturn output
, becausemonitorCount(5,4) is equal to 'return output'
.
Sorry for my terrible explanation, I hope I make sense.