In JavaScript, variables are used to store data values. Think of variables as containers that hold reusable pieces of information like numbers, text, or more complex data types.
myVar
and myvar
are different variables.
You can declare variables using var
, let
, or const
:
// Using var var name = "John"; // Using let let age = 25; // Using const (value can't change) const country = "India";
var
โ Old way, avoid it in modern code.let
โ Use when the value can change later.const
โ Use when the value should stay constant.Variables can store different types of data:
"Hello"
42, 3.14
true
or false
[1, 2, 3]
{name: "John"}
Click the button to see JavaScript variables in action:
const
is best: Prefer const
unless you know the value will change._
or $
(not numbers).let
and const
in modern coding, and name them clearly to keep your code readable.
Help others discover Technorank Learning by sharing your honest experience.
Your support inspires us to keep building!