DEV Community

Discussion on: Know more about function in JavaScript

Collapse
 
codingtheworld777 profile image
codingTheWorld777

Yeah I see what you mean. But let's look around an another example here. It looks similar to the first one, but when you run thΓ­ program, it can run by anyway (although we don't "return" "multiplication()" inside the "callBack()". )

Collapse
 
sargalias profile image
Spyros Argalias

Sorry but I don't fully understand just from the description. Did you have a link to the code? :)

Thread Thread
 
codingtheworld777 profile image
codingTheWorld777

Oh sorry. Here is the link: repl.it/@doHoangKhanh121/StrikingU...

Thread Thread
 
sargalias profile image
Spyros Argalias • Edited

So in this program we're not receiving results or returning anything. We're only printing to the terminal because we use console.log.

Printing to the terminal and returning a result are separate things. One uses console.log and the other uses return.

In this program, we print to the screen on line 7 where we have console.log(${num} * ${i} = ${num * i})

But we never return anything, so on line 17, if we do:

const result = callback(); // this will always be undefined because we're not returning anything from inside callback()

For an example of how return works please see my previous reply :).

Hope that helps :)

Thread Thread
 
codingtheworld777 profile image
codingTheWorld777

Yep. That really helps me to know more about "return" in function. Thank you very much πŸ€—

Collapse
 
codingtheworld777 profile image
codingTheWorld777

I am so confused that I don't need to return the "multiplicationTable()" inside "callBack()" to involve the "callBack()" but finally I can receive the result from return of multiplicationTable() @@.