Understanding a call of "console.log(typeof null);" in a javascript console - Stack Overflow

I've just executed the following code in a Chromium javascript console:console.log(typeof null);Th

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?

Share Improve this question asked Mar 11, 2013 at 17:25 balteobalteo 24.7k67 gold badges236 silver badges437 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 4

undefined 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)

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744312507a4568017.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信