37 sites, 19,920 entries and counting...     Get a free blog; Join a Weblog Network!
Top

The Javascript Keyword var

January 8, 2009

I made this post to remind me that after so many years of using Javascript, I now know what the purpose of the keyword var really is for. The purpose for using the var keyword on a variable is to make it locally scoped. This means that if you use that inside a function, the variable’s scope is gone once the function is finished processing. I never noticed any difference with using a var or not simply because there never came a point in time that I would be having problems with the values of a variable. Until now. When I had problems with the values on a single variable, I was confused why. I tried to add the var keyword thinking, who knows right? And it worked! That was the time I decided to look up the purpose of the var keyword in Google and found the answer.

I laugh at myself why I discovered this until now after so many years. But hey, better late than never right? At least now I know he he he :D.

Comments

4 Responses to “The Javascript Keyword var”

  1. Daily Feed of Informative Blogs. All News Here. » The Javascript Keyword var : Ajax Blog Ajax Tutorial Examples on January 16th, 2009 8:32 am

    [...] @ 7:00 pm   |   December 31, 1969 unknown wrote an interesting post today onHere’s a quick excerptI made this post to remind me that [...]

  2. Colleen on January 19th, 2009 3:34 pm

    And I always thought it was the other way around. There were so few times when it mattered!

  3. TuanAnhBB on May 10th, 2009 8:24 pm

    This usage of var in JavaScript is way different from that in Pascal. I’m always confused when using it :(

    Thanks for the post Jegan!

  4. bob on June 12th, 2009 3:52 pm

    You should have learned JavaScript instead of copying and pasting code!

Got something to say?





Nevis Hotel - Credit Card Consolidation - Debt Consolidation - Renegade Motorhomes
Bottom