Do you know what Is Scope In JavaScript?
Submitted by: MuhammadThe 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
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
Top Website Developer Questions
☺ | Please explain what is CORS? How does it work? |
☺ | Explain me what is the correct way to include JavaScript into your HTML? |
☺ | Tell me the new APIs provided by HTML 5 standard? |
☺ | Do you know what Is SVG And Why Do You Use It? |
☺ | Tell me how Does CSS3 Support The Responsive Web Designing? |
Top Web Developer Categories
☺ | Bootstrap Interview Questions. |
☺ | Front End Web Developer Interview Questions. |
☺ | Typography Interview Questions. |
☺ | Laravel PHP Developer Interview Questions. |
☺ | Junior Developer PHP Interview Questions. |