#1
  1. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2009
    Posts
    677
    Rep Power
    7

    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 and knows not he knows not: he is a fool - shun him. He who knows not and knows he knows not: he is simple - teach him. He who knows and knows not he knows: he is asleep - wake him. He who knows and knows he knows: he is wise - 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,945
    Rep Power
    4033
    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