为什么控制台中的变量声明始终返回"undefined"? [英] Why do variable declarations in the console keep returning "undefined"?

查看:331
本文介绍了为什么控制台中的变量声明始终返回"undefined"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用最新的Firefox(4.0.1)和Firebug(1.7.2).

I am using the latest Firefox (4.0.1) and Firebug (1.7.2).

每当我在控制台中输入变量声明时,都会返回斜体的未定义"警告.

Any time I enter a variable declaration into the console, an italicized "undefined" warning is returned.

例如,如果我输入"var x = 5;"那么响应是未定义",而不是"5".

So for example if I enter "var x = 5;" then the response is "undefined", rather than "5".

然后,如果我在控制台中输入"x",则将返回正确的5值.但是,错误/警告有点令人讨厌,真的想知道原因和解决方法,如果我是唯一遇到这种情况的人.

Afterward if I enter "x" into the console, the proper value of 5 is returned. However the error/warning is a bit of a nuisance, would really like to know the cause and resolution, and if I'm the only one experiencing this.

有趣的是,如果我不使用"var",而只是使用"x = 5"声明值,那么将显示正确的行为,并且控制台中将返回"5".

Interestingly if I don't use "var" but just declare the value using "x=5" then the correct behavior exhibits and "5" is returned in the console.

推荐答案

(这只是一个猜测,我不是Java语言规则或Firebug细节方面的专家.)

(This is just a guess, I'm not an expert on the details of Javascript's language rules or on Firebug.)

控制台向您提供的反馈是对您输入的行进行评估的结果.我假设 declaration var x = ...是一个没有值的语句,而简单赋值(x = ...)符合C的传统,并且一切都是表达"的态度是功能语言的一种表达式,其计算结果为分配的值.

The feedback the console gives you is the result of the evaluation of the line you entered. I assume the declaration var x = ... is a statement that doesn't have a value, while simple assignment (x = ...) is, in line with the C heritage and the "everything is an expression" attitude of functional languages, an expression that evaluates to the assigned value.

这篇关于为什么控制台中的变量声明始终返回"undefined"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆