Hi Abhijit Paul,
By default all variables in JavaScript are global, meaning they retain their values
everywhere in a scripted web page. To make a variable local to a block (such as a
function), declare it with the keyword var. Here's a n example:
// here 'i' is a global counter variable that could, if reused
// elsewhere in this script, create hard-to-find errors
for( i=1; i<=N; i++ ) {
[code to iterate]
}
// to ensure that 'i' exists only in the scope of this
// counter, use var:
for( var i=1; i<=N; i++ ) {
[ ... ]
}
hope you got your answer..
Nov 23, 2009