dcsimg
www.webdeveloper.com
Results 1 to 3 of 3

Thread: Defining variables differences

Hybrid View

  1. #1
    Join Date
    Apr 2010
    Location
    Brooklyn NY
    Posts
    104

    Defining variables differences

    What's the difference between defining a variable with 'var' before, versus defining without it?

    ex.

    var s = 5;

    Vs.

    s = 5;

  2. #2
    Join Date
    Aug 2006
    Location
    Michigan
    Posts
    17
    This may not be the complete reason, but declaring with the var insures it is local to the proceedure, defining it without var may take on the instance of a variable at a higher level that has the same name.

  3. #3
    Join Date
    Aug 2007
    Posts
    3,767
    Yep. With var, it's local, without var if undefined, it's global. I personally dislike declaring variables like that, I think it's bad practice.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles