最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin9浏览0评论

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)

发布评论

评论列表(0)

  1. 暂无评论