# JavaScript Variable Declarations: var vs let vs const.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1697438853765/e2889270-fd86-48b4-a956-1f1a4c913c1c.gif align="center")

Hello everyone, today we are going to discuss JavaScript Variable Declarations and the difference between them.

There are three ways to declare variables in JavaScript `var` `let` and `const` .

So, What's the difference between and why do we even bother?

## Var

If we declare a variable with `var` it gets **hosited** on top of its containing scope or we say this is global scope. And also variable delared with var it is reassingable.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1697435908621/dd237f94-53b7-4711-ab7f-9bf176f5227a.png align="center")

## Let

Now let's declare a variable with `let`.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1697435966932/a05d9cef-89e5-4121-b8ab-1979d0ba5646.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1697436002221/ce875f93-5dd8-4bc4-8f89-148fdc2664f4.png align="center")

Now we have solved the problem of hoisting but another problem is remaining and that is verable reassigning.

## Const

Last but not least let's see when we declare a variable with `const`.  

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1697435983558/cda43dd9-d1cd-4ed8-aefb-4064627cf111.png align="center")

So, Now we have solved both problem of hoisting and reassigning.

# Conclusion

so, now the of which one to use totally depends on your specific requirements. The use of Use `var` sparingly, as it has been largely replaced by `let` and `const` in JavaScript. You should use `let` when you need variables with **reassignable** values within a **block scope.** For variables that should not be reassigned, you should use `const` for maintainable robust code.

Thanks, everyone hanging in there till the last ❤️!!

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1697438630281/4e591eba-1527-48ca-b43d-7846dd8c9efd.gif align="center")
