September 9th, 2013, 10:52 AM
-
Defining variables...
Well, I see how to do everything, but the question is what truely is needed. If a variable doesn't exist, MUST you declare it via 'var varname'? Or is it ok to declare by assigning a value like 'varname = "Some value."'?
He who knows not that he knows not is a fool, ignore him. He who knows that he knows not is ignorant, teach him. He who knows not that he knows is asleep, awaken him. He who knows that he knows is a leader, follow him.
September 9th, 2013, 11:27 AM
-
Unless you declare a variable using the var keyword, then you are not actually working with a variable. Rather, what happens is you just end up implicitly creating a new property on the global object (window). In most cases, it looks and feels the same as a variable, but there is a technical difference between the two situations.
You should always declare your variables using var blah to prevent scope issues and prevent mucking up the global object with unnecessary properties
Comments on this post
Last edited by kicken; September 9th, 2013 at 03:34 PM.
Recycle your old CD's
If I helped you out, show some love with some reputation, or tip with Bitcoins to
1N645HfYf63UbcvxajLKiSKpYHAq2Zxud