Is it correct to assume that omitting var
from a local
variable will
ALWAYS override a global
of the same name, if it's also missing var
?
Also, is there any merit to using var
with creative license.
So there's a frame of reference, here is what I discovered
from riddles I created for a previous post.
In Riddle #3,
- omitting the
var
froma = 5
overrides itsglobal
counterpart b
remains polarized betweenlocal
andglobal
- the
alert()
at the bottom returns 5*5+4+15 - 4 is the
local
b
. 15 is theglobal
b
, declared on line 25
In Riddle #2,
- omitting the
var
fromb = 4
overrides itsglobal
counterpart a
remains polarized betweenlocal
andglobal
- the
alert()
at the bottom returns 5*3+4+4 - - 5 is the
local
a
. 3 is theglobal
a
, declared on line 11
In Riddle #1,
- omitting the
var
from bothlocal
variables overrides ALLglobal
counterparts - There is no distinction between
local
andglobal
variables. - the
alert()
at the bottom returns 5*5+4+4 - Only variables declared inside the
function
are recognized