#1
  1. No Profile Picture
    Super Moderator
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jun 2009
    Location
    Hartford, WI
    Posts
    1,332
    Rep Power
    24

    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.
  2. #2
  3. Wiser? Not exactly.
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    May 2001
    Location
    Bonita Springs, FL
    Posts
    5,943
    Rep Power
    4037
    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

    • Triple_Nothing agrees : Thank you. :thumbs:
    Last edited by kicken; September 9th, 2013 at 03:34 PM.
    Recycle your old CD's, don't just trash them



    If I helped you out, show some love with some reputation, or tip with Bitcoins to 1N645HfYf63UbcvxajLKiSKpYHAq2Zxud

IMN logo majestic logo threadwatch logo seochat tools logo