Why does calling console.log()
function test1() {
console.log('test1')
}
// or ES6
const test2 = () => { console.log('test2') }
Give the same results as returning console.log()
function test3() {
return console.log('test3')
}
// or ES6
const test4 = () => console.log('test4')
test1() // -> test1 undefined
test2() // -> test2 undefined
test3() // -> test3 undefined
test4() // -> test4 undefined
While I understand a function without an explicit return
will always return undefined
, it seems counter-intuitive to me that returning the result of console.log()
gives the exact same output.