2

Hello friends I was stuck with the following code output.

x = 1;
var a = 5;
var b = 10;

var c = function(a, b, c) {

            var x = 10;
            document.write(x); 
            document.write(a); 

                var f = function(a, b, c) {
                    b = a; 
                    document.write(b+"\n"); 
                    b = c;
                    var x = 5;
                }

            f(a,b,c); 
            document.write(b); 
 }

c(8,9,10);
document.write(b); 
document.write(x);

the expected output is : 10 8 8 9 10 1 but was confused with the output why the value of b in 10 8 8 9 10 1 is not 9. How the value of b got 10 instead. Please help me to understand the concept.

Yubraj Pokharel
  • 477
  • 8
  • 23
  • 1
    hello Syco. let me tell you just one thing, in this case, in the global scope, the var b is never modified, is set to 10 and remains 10. inside the function ser to c, we have a new var b, that is also used to evaluate the function in f, in which we define (again) a new var b, that is modified twice, but only in the scope of this function, not in the global scope. if needed, you can play with it here: https://repl.it/Brrt/0 – JulioCT Mar 01 '16 at 20:47

0 Answers0