当我运行“varvariable=true;”时在 Chrome 控制台中,我返回“未定义”:
> var variable = true;
undefined
但是当我在没有“var”的情况下运行时,它返回 true:
> variable = true;
true
为什么它返回“undefined”和“var”?
这很令人困惑,因为我预计它会返回 true。
最佳答案
第一个是语句,第二个是表达式。虽然不完全相同,但与 C 的规则类似:
// A statement that has no value.
int x = 5;
// An expression...
x = 10;
// ...that can be passed around.
printf("%d\n", x = 15);
关于javascript - "var variable"返回未定义?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35546113/