View Single Post
Old 04-23-2009, 05:39 PM   #3 (permalink)
Salathe
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
Salathe is on a distinguished road
Default

Quote:
Originally Posted by allworknoplay View Post
Now I keep staring at that code, and I don't see what he's talking about? The function has only one variable in it's scope, and that's the Y variable in which he returns it.
Sure, there's only one variable used (aside: not declared) inside the function but the variable x is still available to be used. For example:

JavaScript Code:
var x = 5;
var n = function(){
    var y = 10;
    return x + y;
};

// … some time later
x = 113;
alert(n()); // 123
 
Salathe is offline  
Reply With Quote