JavaScript Variables
Variables are containers used to store data
There are 4 ways to declare variables in javascript:
- Using const
- Using let
- Using var
- Automatically
Declaring Variables in JavaScript
Creating a variable in JavaScript is called declaring a variable.
Before ES6 (2015): Variables were declared only with var, which is function-scoped and global-scoped, causing issues like hoisting and global pollution.
ES6 Introduction: let and const were introduced to provide safer alternatives for declaring variables.
Scope: let and const are block-scoped (limited to { } block) or global-scoped, reducing errors compared to var.