I'm new to JavaScript, and I try to play around with it to understand all in-and-outs. I write
function greet() {
console.log("Hi");
};
console.log(greet());
And the result of it in the console is
> Hi app.js:2
> undefined app.js:4
I assume this is because greet()
inside console.log
first calls the function, which prints out "Hi"
. We get first line of log. But where did the second line come from?
Then I thought because Hi
is overall result of greet()
, then console.log
basically calls variable Hi
, but in this case the result would be is not defined
, not undefined
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…