Difference Between var, let and const Keywords in JavaScript
## Introduction
JavaScript is an object-oriented scripting language that is used to develop web applications. It has a set of keywords that are used to create, store, and manipulate variables in the code. `var`, `let` and `const` are the three keywords that are used to declare a variable in JavaScript.
The main difference between `var`, `let` and `const` is their scope and the way they are used. `var` is a keyword that is used to declare a variable, which has a global scope, meaning it can be accessed from anywhere in the code. `let` is a keyword that is used to declare a variable with a block scope. It can be accessed only within the block it is declared in. `const` is a keyword that is used to declare a constant variable, which has a block scope and cannot be reassigned.
In this article, we will be discussing the differences between `var`, `let` and `const` keywords in JavaScript and the best way to use them. We will also look at some of the advantages and disadvantages of using each keyword.
Worried About Failing Tech Interviews?
Attend our webinar on
"How to nail your next tech interview" and learn
.png)
Hosted By
Ryan Valles
Founder, Interview Kickstart

Our tried & tested strategy for cracking interviews

How FAANG hiring process works

The 4 areas you must prepare for

How you can accelerate your learnings
Register for Webinar
# Var, Let and Const Keywords in JavaScript
The three keywords `var`, `let` and `const` are used in JavaScript to declare variables. The differences between them are important to understand in order to use them appropriately in your code.
## Var
`Var` is the oldest keyword for declaring variables in JavaScript and was introduced in the first version of the language. Variables declared with `var` are considered to have **function scope**, meaning that they are accessible within the function in which they were declared. If a variable is declared outside of a function, it will be accessible throughout the entire program.
## Let
`Let` was introduced in ES6 and is similar to `var`, but with the addition of **block scope**. Variables declared with `let` are accessible only within the block in which they were declared, for example a for loop or an if statement.
## Const
`Const` was also introduced in ES6 and is used to declare **immutable** variables. This means that any variable declared with `const` cannot be reassigned or redeclared.
## Sample Code
Here is an example of how each variable type can be used:
```javascript
// Var
var x = "Hello World!";
console.log(x); // Prints "Hello World!"
// Let
let y = 10;
console.log(y); // Prints 10
// Const
const z = true;
console.log(z); // Prints true
```