Do you know what Is Scope In JavaScript?

Submitted by: Muhammad
The general meaning of scope is the accessibility of functions and variables in an application. Usually, we use them in two ways i.e. Local and Global.

A) Local Scope.
If we declare a function or variable inside a function, then we can access it only inside that function.

// code here can not use myLocalVar

function myFunction() {
var myLocalVar = "I'm Local";

// code here can use myLocalVar

}
B) Global Scope.
Declaring a variable anywhere on the page would mean that we can access it from any of the functions on that page.

var myGlobalVar = "I'm Global";

// code here can use myGlobalVar

function myFunction() {

// code here can use myGlobalVar

}
Submitted by: Muhammad

Read Online Website Developer Job Interview Questions And Answers