//I have written the below code in JS.
var output = [];
var num =1 ;
function fizzBuzz(){
var a = output.push(num);
num ++;
console.log(output);
}
// Each time I call the function the values are incremented by 1. So the output is:
fizzBuzz();
[1]
fizzBuzz();
[1,2]
fizzBuzz();
[1,2,3]
// And so on:
// However when I write the code like this:
var output = [];
function fizzBuzz(){
var num =1 ;
var a = output.push(num);
num ++;
console.log(output);
}
// The output is different.
fizzBuzz();
[1]
fizzBuzz();
[1,1]
fizzBuzz();
[1,1,1]
// and so on.
// May I know the logic behind this?