OpenSource For You

Scope

-

The scope of the variable is quite important in JavaScript and it is slightly different from the normal programmin­g languages.

Local variable: If a variable is declared with the keyword ‘var’ inside the function, we call it a local variable. The scope of the variable is limited to that function only.

Global variable: If you declare any variable without the keyword ‘ var’, it is considered as a global variable. That variable will be the part of your root object, i. e., a window object. Memory will not be released after its execution. So it is not advisable to use global variables for any reason.

Newspapers in English

Newspapers from India