iTMDev Technologies Interview Question for Developers


Country: United States




Comment hidden because of low score. Click to expand.
0
of 0 vote

In JavaScript, scope refers to the visibility of a variable or function. There are two types of scope in JavaScript:

Global scope: A variable with global scope is available across the entire program. These variables can be accessed from anywhere in the program because they are declared outside of any specific function.
Local scope: A variable with local scope is only available within the function in which it is declared. These variables cannot be accessed from outside of the function.

Here is an example of global scope:var myVar = "This is a global variable";

function myFunction() {
console.log(myVar); // This will work because myVar is in global scope
}

myFunction();
In this example, the variable myVar is declared outside of any function, so it has global scope. This means that it can be accessed from anywhere in the program, including the myFunction() function.

Here is an example of local scope:function myFunction() {
var myVar = "This is a local variable";

console.log(myVar); // This will work because myVar is in local scope
}

myFunction();
In this example, the variable myVar is declared inside the myFunction() function, so it has local scope. This means that it can only be accessed from within the myFunction() function.

- abhishekpeddi123 August 31, 2023 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

You forgot about reduced scopes for let variables.

- Ezequiel September 28, 2023 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More