---
title: "Comment by Muhammad Saleh Bulah on \"Variable Declaration in JavaScript\" | Hashnode"
description: "Yeah I have gotten fully understand of this concept of how to declare tmtge variable, but I want more explanation on scope (Block scope) Thank you!"
url: "https://hashnode.com/posts/variable-declaration-in-javascript/5ef8f7aef6897a1bb5e260d5/comment/5f020d587b0c40081e9f1594"
---

[Discussion](https://hashnode.com/posts/variable-declaration-in-javascript/5ef8f7aef6897a1bb5e260d5)

Comment [Variable Declaration in JavaScript](https://hashnode.com/posts/variable-declaration-in-javascript/5ef8f7aef6897a1bb5e260d5)

[Muhammad Saleh Bulah](https://hashnode.com/@Muhammadbulah)

[Jul 5, 2020](https://hashnode.com/posts/variable-declaration-in-javascript/5ef8f7aef6897a1bb5e260d5/comment/5f020d587b0c40081e9f1594)

Yeah I have gotten fully understand of this concept of how to declare tmtge variable, but I want more explanation on scope (Block scope)

Thank you!

[Chenemi Zekeri](https://hashnode.com/@chenemi)

[Jul 5, 2020](https://hashnode.com/posts/variable-declaration-in-javascript/5ef8f7aef6897a1bb5e260d5/comment/5f020d587b0c40081e9f1594#reply-5f024c2d7b0c40081e9f165d)

Hi Muhammad! As explained above, a block is a portion of code enclosed by curly braces: {}. An if statement, for example, would look something like this:

```
let y = 2;
if (y = 2) {
    let x = 5;
}
```

In the above example, `x` cannot be accessed outside that block. If we were to run this:

```
let y = 2;
if (y = 2) {
    let x = 5;
} 
console.log(x);
```

The console would return a reference error; because outside that block, `x` behaves as if it has not been declared at all. Variables declared within a block using let or const cannot be referenced outside that block, and will essentially not be 'recognized' outside of that block.
