Undefined in console

clearly defines a variable, why output undefined.

Mar.14,2021

clipboard.png


" < " is the content of the command return that you enter. Define a variable that does not have return information

.

for example, you execute the following two commands in the console:

const a = () => 1 // areturnundefined

a() // areturn11

declares that a variable will not return a value, and assigning a value to a variable will return the value itself


because the console attempts to print the result of an expression evaluation by default.
for example:

> 1 + 2
3
The

console tries to print the result of the expression evaluation 1x2 , so it displays 3

.

similarly, if you

> console.log(2)
2
undefined

first the result of the expression is: print 2 (note that it is not return 2 but print 2), and then the console tries to print the calculated (return) result of console.log (). It does not return any results, so it displays undefined

so, I don't have to explain this.

var x = 8
undefined
Menu