Skip to content

added hyperlinks to eachscope #240

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Oct 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions en/interview-questions/basic-level.md
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,11 @@ In general terms, the scope will let us know at a given part of code, what are v

There are three types of scopes in JS:

- Global Scope
- Local or Function Scope
- Block Scope
- [Global Scope](#global-scope)
- [Local or Function Scope](#function-scope)
- [Block Scope](#block-scope)

<a id="global-scope"></a>
**Global Scope**: Variables or functions declared in the global namespace have global scope, which means all the variables and functions having global scope can be accessed from anywhere inside the code.

```js
Expand All @@ -221,6 +222,7 @@ function sendMessage2() {
sendMessage2(); // Returns “Hello world”
```

<a id="function-scope"></a>
**Function Scope**: Any variables or functions declared inside a function have `local/function scope`, which means that all the variables and functions declared inside a function, can be accessed from within the function and not outside of it.

```js
Expand All @@ -236,6 +238,7 @@ console.log(a); // Throws reference error since a is written in local scope and
multiplyBy2(); // Throws reference error since multiplyBy2 is written in local scope
```

<a id="block-scope"></a>
**Block Scope**: `Block scope` is related to the variables declared using let and const. Variables declared with var do not have block scope. Block scope tells us that any variable declared inside a block `{ }`, can be accessed only inside that block and cannot be accessed outside of it.

```js
Expand Down
Loading