Global & Local variables in Javascript
问题 I have one variable and two functions . The variable is used by both. and the first function is changing the variable value (globally) each time it's used by it . This is what I want but it is not working with me . x = 1; function f1() { x = x + 1; // use x } function f2() { // use x } I've read other threads but x is always 1 which is very frustrating :| added: actual code <script type="text/javascript"> function S4() { return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);