I've just executed the following code in a Chromium javascript console:
console.log(typeof null);
The result is seen in the following screen capture:
I am just wondering what the greyed <- undefined
line means. Can anyone please advise?
I've just executed the following code in a Chromium javascript console:
console.log(typeof null);
The result is seen in the following screen capture:
I am just wondering what the greyed <- undefined
line means. Can anyone please advise?
1 Answer
Reset to default 4undefined
It's the last statement's return value.
> 5
5
> "Hello World"
"Hello World"
> (function(){ return 6})();
6
Whenever a function in JavaScript does not explicitly return anything, it returns undefined
by default.
To sum up the process, object
is the result of your console.log(typeof null)
call. Your code ran, logged object
to the console then printed the return value of the function call which is undefined
.
This is probably the result of how eval
works. The console in the developer tools in chrome probably runs eval
on your code. eval
returns the value of the last statement/expression you put in it
> eval(5);
5
(Note: I know this is fairly obvious, but when using eval in an example I feel the need to mention that while a REPL is an excellent use case for eval
we must remember that eval is evil)