Return statement in fuctions

hello!
what is the difference between return statement in functions and console.log() as both are doing the same thing, so why there is need of return statement in JavaScript?

1 Like

function countup (n){
for (let i = 1; i<=n; i++)
console.log(i)
}
console.log (countup(9))

function countup (n){
for (let i = 1; i<=n; i++)
return i
}
console.log (countup(9))

when i run the first code i displayed 1234…9 but when i run the second one it displayed 1
why is that

ok its like when we use console.log it will executes till given condition gets false whereas in return statement it executes and terminates after the execution no matter what is the condition given to it… like that or something else?

1 Like