I've just started developing in Javascript, and have been reading up on scope and execution context. I was wondering if there's a difference between this:
function fun1 () {
var x = 1;
function fun2 () {
x = x*2;
alert(x);
}
}
and:
function fun1 () {
var x = 1;
fun2(x);
}
function fun2 (x) {
x = x*2;
alert(x);
}
Would there be reasons to use one over the other? Do they have any performance/security implications (or other unexpected implications for beginner JS developers)?
fun2in the first example.fun1, inside it's not.fun1