There are two types of variables in JavaScript. Global variables have global access and are declared outside of any function. Local variables are those declared inside of function. Lexical Scoping(Nested JavaScript Function) means that in a nested group of functions, the inner functions have access to the variables and other resources of their parent scope. Global variable:- Global variable declares & initialize outside the function, & accessible in from anywhere in the code. The global variable always stored in memory even function execution finish, it always keeps in memory or always accessible from anywhere in the code. Example 1 var message= "hello i am global variable" ; //global variable function a (){ console.log(message); // output: hello i am global variable } function b (){ console.log(message); // output: hello i am global variable } function a() function b() In above example message is a global variable, it can be acces
Amritanjali's blog UI Source on UI related technologies like Angular, TypeScript, JavaScript, HTML, CSS.