Question about console.log()

Question about console.log()
0

#1

I have the following code:

console.log("Hello World!")

I am returned the string “Hello World!” alongside a link to the debugger attached to the Javascript VM which ran that code. However below all of that I am returned “undefined”. Could someone explain to me what the undefined is referring to?


#2

If I am not mistaken, that last line will always show the last evaluation. console.log does not return a value, so it shows undefined. If you were to write a = 5; It would display 5.

If you put the following in the console:

function returnSixAndConsoleLogTwo(){ console.log(2); return 6;}; returnSixAndConsoleLogTwo();

It will display the value 2 on one line and since 6 was the last evaluation, it displays the 6 also, because it was the result of the function call.