13/11/2025
Learn JavaScript
Lesson -2
Variable
What is variable
A variable is a named storage location in programming that holds data which can change during program ex*****on.
What Is a Variable?
Definition: A variable is a symbolic name associated with a value and whose associated value can change.
Purpose: It allows programmers to store, retrieve, and manipulate data dynamically throughout a program’s lifecycle.
Key Characteristics
Name (Identifier): The label you give to the variable (e.g., userName, score, favFruit).
Value: The actual data stored (e.g., "Mohammad", 42, 'apple').
Type: The kind of data it holds—like string, number, boolean, etc.
Scope: Determines where the variable can be accessed (e.g., local vs global).
Lifetime: How long the variable exists in memory during ex*****on.
Types of Variables
Local Variable: Declared inside a function or block; accessible only there.
Global Variable: Declared outside any function; accessible throughout the program.
Constant: A variable whose value cannot be changed once assigned.
Why Use Variables?
To make code dynamic and flexible.
To improve readability and maintainability.
To store user input, configuration, or intermediate results.
es5 var
es6 let, const
declaration: var a;
Initilization: var a=20;
reintilization: a=30;