调用foo()后x和y值是什么?

时间:2012-08-17 06:00:25

标签: javascript

var x = 'hello';
var x = 'world';

function foo(){
    var y = x = 'hello from foo';
}
foo();

它是x ='你好来自foo',y ='你好来自foo'?

1 个答案:

答案 0 :(得分:2)

使用您的代码,x'hello from foo'yundefined

foo中,您已将'hello from foo'分配给全局变量x,然后将其x分配给本地变量y