Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Declaring two variable with the same name

Is it possible to call the same name variables which set outside of the function?

var a = $(window).width(); // I want to call this variable
if(!$.isFunction(p)){
    var a = $(window).height(); // Not this one
    alert(a);
}

FIDDLE

like image 470
Tukhsanov Avatar asked May 17 '14 10:05

Tukhsanov


1 Answers

In this case, you have actually redefined the value of a. There is absolutely no way of referencing a different variable with the same name, as it just acts as a redefinition.

like image 136
The6P4C Avatar answered Sep 24 '22 21:09

The6P4C