One of the biggest passwords in JavaScript is shutdown. He is the subject of many questions on job interviews at FAANG companies. In this article, we’ll talk about fence and goal, illustrate the concepts with simple examples, and then conclude with a sample question from an interview with one of the biggest tech giants.
When someone tells you that something is or is not part of a project, what does it mean?
I would like to think of a periscope or a telescope when I think of the answer to this question. These tools show us all kinds of things within the limits of the lens he’s got: he’s in field. If it is out of range, you cannot see past the diameter of the lens. And to illuminate something outside the diameter is not possible. You should think about this as we talk about three very important and distinct types of scopes in JavaScript: local, global, and lexical.
Local scope
The local scope is the smallest of the three scopes we’ll be discussing today. When we declare a function, anything enclosed in square brackets ({}) is considered local to the function. When the JavaScript engine reads the function, it declares the variables; when it ends, it will destroy the variables.
As you can see, when "console.log ()" the result of the invoked greeting function, we are able to access to the WebsiteName after the function was played. This gives us the "Hello Karma Career‚" channel that we were looking for. As already mentioned the console.log () of the variable that was declared in the function generates an error because it cannot be defined.
, the reason WebsiteName is undefined is because variables are created inside functions when called, and then destroyed when the terminal instruction is executed. Anything outside the function does not have access to things inside the function, unless it has a particular configuration.
global reach
This next field is pretty much a literal translation of the phrase. A global scope takes elements declared outside of a function and reserves them in a space where all scripts, methods, and functions can access and use them for their own logic.
What does the above code do if console.log ()
counts at the end of the code ? What do you hope will happen?