Today i encountered a typical thing. So far what i knew that JavaScript had a scope inside a function but it was not there. I think in newer version of JavaScript it is introduced, in older version there may be. Anyway .....
Have a look at my code snippet ....
[code=javascript]
function test(){
var s = "Hello!";
var s = "Hi!";
alert(s); //it alerts the latest value of s, and here is no duplicate definition of s
}
[/code]
[code=javascript]
function test(){
//some code
}
function test(){
//some latest code
}
[/code]
Whenever i call test it executes the latest code, here is also not duplicate definition. How JavaScript handles it?
Please explain.
Have a look at my code snippet ....
[code=javascript]
function test(){
var s = "Hello!";
var s = "Hi!";
alert(s); //it alerts the latest value of s, and here is no duplicate definition of s
}
[/code]
[code=javascript]
function test(){
//some code
}
function test(){
//some latest code
}
[/code]
Whenever i call test it executes the latest code, here is also not duplicate definition. How JavaScript handles it?
Please explain.
Comment