The Javascript Keyword var

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.

4 Responses to The Javascript Keyword var
  1. bob
    June 12, 2009 | 3:52 pm

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

  2. TuanAnhBB
    May 10, 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!

  3. Colleen
    January 19, 2009 | 3:34 pm

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

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