Links

Lists

Latest Updates

Ruby On Rails List
Python list
Advanced Java
The JavaScript List
Apache Users
Full Disclosure
Linux Security

Search the archives!


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Javascript] "var" keyword


  • From: javascript@xxxxxxxxxx (Peter-Paul Koch)
  • Subject: [Javascript] "var" keyword
  • Date: Tue, 23 Apr 2002 08:10:49 +0000

>I can declare my variables with the "var" keyord, or not. I can delete a 
>variable with "delete" keyword or not. But what is the real diference and 
>how should I do?

If you declare a variable inside a function by using the 'var' keyword, it 
becomes a local variable:

var theVar = 'global';

function doSomething()
{
  alert (theVar) // gives 'global'
  var theVar = 'local';
  alert (theVar) // gives 'local'
}

As to delete, I never use it and I seem to remember Flanagan said it's not 
very important in JavaScript.

ppk

_________________________________________________________________
Chat with friends online, try MSN Messenger: http://messenger.msn.com