GeSHi (Javascript):a = 3;b = 2; function line(x) { a = 5; b = 4; return a*x + b} //b should be 17b = line(a) - b;alert(b); //c should be 21var c;c = line(a) - b;alert(c);
GeSHi (Javascript):a = 3;b = 2; function line(x) { var a = 5; var b = 4; return a*x + b;} //b should be 17b = line(a) - b;alert(b); //c should be 21a = 0;c = line(a) + b;alert(c);
The code to the right behaves unexpectedly because of scope issues. Run it and try to figure out what is going on. Fix it using var
GeSHi (Javascript):a = 3;b = 2; function line(x) { var a = 5; var b = 4; return a*x + b} //c should be 21c = line(a) + b;alert(c); //b should be 17b = line(a) - b;alert(b);
Хм, "CodeAcademy", която те занимава с глобални променливи във function scope не си заслужава името