DEV Community

Cover image for JavaScript Struggles - Part 1 | Defending Variables
‘Abdelraḥman Dwedar 👨🏻‍💻🇵🇸
‘Abdelraḥman Dwedar 👨🏻‍💻🇵🇸

Posted on • Edited on

JavaScript Struggles - Part 1 | Defending Variables

Defending variables in JS have its own way.

We have three ways to defend a variable let, var, const.

Var Let Const
Changeable
Block Scope
Global Scope
Make Arrays

We mostly use let because of the block scope which I'll explain in the below. 👇🏻


Let

The keyword let makes a variable only useable within the scope it made in, you can't use it outside that scope.

E.g.


Var

The keyword var makes a global variable, you can use it everywhere in the code.

E.g.


Const

The keyword const makes an unchangeable variable, you can't change its value.

E.g.

Top comments (1)

Collapse
 
abdelrahman_dwedar profile image
‘Abdelraḥman Dwedar 👨🏻‍💻🇵🇸

Thaks for sharing that with me, sorry for the mistake. 🙏🏻
I've heard that the block scope is taking less memory space then the general. Thanks for clearifying. 👍🏻👍🏻