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?

34 of 51 people (67%) answered Yes
Recently 7 of 10 people (70%) 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
}