faqts : Computers : Programming : Languages : JavaScript : Language Core : Variables

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

33 of 50 people (66%) answered Yes
Recently 6 of 10 people (60%) answered Yes

Entry

How do I create local variables for a function?
How do I create local variables?
How does JavaScript handle global variables?

Oct 24th, 2000 22:17
Tim Powell,


To make sure that a variable is only available in a function, you need 
to use the var keyword when declaring it.

j = 20;
i = 10;

function func()
{
   i = 1;     // Changed the value of global variable (since it exists)
   var j = 1; // local variable - j is still 20 outside this function
}