1) Scope: 1) Scope in JavaScript actually determines the accessibility of variables and functions at various parts in one’s own code or program. 2) Scope will help us to determine a given part of a code or a program, what variables or functions one could access and what variables or functions one cannot access. 3) Within a scope itself, a variable or a function, or a method could be accessed. Outside the specified scope of a variable or function, the data cannot be accessed. 4) There are three types of scopes available in JavaScript: Global Scope, Local / Function Scope, and Block Scope. //global scope let global = "Swati" ; function func1 () { return global; } function func2 () { return func1 (); } console. log ( func2 ()); //local scope function func1 () { let a = 2 ; let multiply = function () { console. log (a * 5 ); } multiply (); } func1 (); //Block scope { let a = 5 ; } console. log (a); 2) Scope Nesting: //Bl...
Comments
Post a Comment