Keen eyes

Ian Kelly ian.g.kelly at gmail.com
Sun Jan 17 02:37:00 EST 2016


On Jan 17, 2016 12:16 AM, "Steven D'Aprano" <steve at pearwood.info> wrote:
>
> On Sun, 17 Jan 2016 10:25 am, jonas.thornvall at gmail.com wrote:
>
> > double use of j in two different functions
>
> Are you using a global variable called "j" as a loop variable? That sounds
> like a terrible idea.
>
> You should use local variables. Then a function with a local variable j
> cannot possibly effect another function with a local variable also called
> j.
>
> Wait... is somebody going to tell me that Javascript defaults to global
> variables inside functions?

Technically it defaults to non local. The var statement allocates a
variable within the current scope. Otherwise it searches up the chain of
parent scopes for a matching variable, terminating at the global scope.

I believe Lua also works this way.



More information about the Python-list mailing list