[英]Why does the console print undefined when I assign a variable?
Hey pretty simple task I am trying to do.... I'm trying to take the text in my textbox and assign it to a var. 嘿,我正在尝试做的非常简单的任务。...我正在尝试将文本放在文本框中,并将其分配给var。 When I run without the var I am getting text but if I assign it to a var I get undefined.
当我不使用var运行时,我正在获取文本,但是如果将其分配给var,则无法定义。 Could someone explain this to me as it is very confusing to me?
有人可以给我解释一下,因为这让我很困惑?
TL;DR : It does not. TL; DR :没有。
You can see content of your variable test
, il will output the same thing as before. 您可以看到变量
test
内容,il将输出与以前相同的东西。 In fact it is the variable assignement that returns the undefined
you see here. 实际上,变量赋值返回您在此处看到的
undefined
。
For instance: 例如:
var test = 'Hello' // => undefined
test // => 'Hello'
Another case is printing your variable with console.log
. 另一种情况是使用
console.log
打印变量。 If you do so, the return value will be undefined
but the output will be your variable content ( Hello here). 如果这样做,则返回值将是
undefined
但输出将是您的变量内容(此处为Hello )。
console.log(test) // return: undefined / print: Hello
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.