Scope In JavaScript

Yahya Gok
2 min readAug 19, 2021

Scope is the accessibility of variables, functions, and objects in some particular part of your code during runtime. In other words, scope determines the visibility of variables and other resources in areas of your code.(1)

In JavaScript if we declare variable outside of a function and want to use this variable inside the function, it runs greatly. Below picture is an example for that.

We could be able to declare a variable inside the function, the code would be running same. Below example shows same result.

Now, from here when we do console.log(exampleVariable), we will get an ReferenceError. We no longer available to exampleVarible outside of function. Because we declare that variable inside the function and it is visible inside the function. Below picture shows the result.

Resources

--

--