Because you passed a param called x, which is the same name as your global var. Try this out:
var x = 5; function test2(y) { x = y; } test2(8); alert(x);
1.4m articles
1.4m replys
5 comments
56.9k users