---
title: "Discussion on \"Variable Declaration in JavaScript\" | Hashnode"
description: "Discussion on \"Variable Declaration in JavaScript\". Summary  \nThis tutorial will cover the following concepts:•    Variables in JavaScript•    Declaration and Initiation of Variables•    The var, let, and const keywords•    Variable Scope and Hoisting  \nWHAT ARE VARIABLES  \nVariables in JavaScript are..."
url: "https://hashnode.com/posts/variable-declaration-in-javascript/5ef8f7aef6897a1bb5e260d5"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [Variable Declaration in JavaScript](https://chenemi.hashnode.dev/variable-declaration-in-javascript?utm_source=hashnode&utm_medium=feed)

Summary This tutorial will cover the following concepts:• Variables in JavaScript• Declaration and Initiation of Variables• The var, let, and const keywords• Variable Scope and Hoisting WHAT ARE VARIABLES Variables in JavaScript are...

Jun 28, 2020 · 5 min read · chenemi.hashnode.dev  
Read the article

-   [#javascript](https://hashnode.com/tag/javascript)
-   [#variables](https://hashnode.com/tag/variables)
-   [#hoisting](https://hashnode.com/tag/hoisting)
-   [#scope](https://hashnode.com/tag/scope)
-   [#beginners](https://hashnode.com/tag/beginners)

## Written by

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

@chenemi

  
[View profile](https://hashnode.com/@chenemi)

Front-End Developer

## Responses 1

Markdown supported · ⌘↵ to post

[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.
