Why the result seems different when I put the variable inside/outside of the function?
Variable sound outside the function:
var sound = "" ;
var laugh = function(num) {
for (var x = 0 ; x < num ; x++) {
sound = sound + "ha" ;
}
sound = sound +"!";
return sound;
}
console.log(laugh(3))
Variable sound inside the function
var laugh = function(num) {
for (var x = 0 ; x < num ; x++) {
var sound = "" ;
sound = sound + "ha" ;
}
sound = sound +"!";
return sound;
}
console.log(laugh(3))