
310 views
JavaScript Variable
The variable is a named container used to store a value. It’s like a label that points to a memory location where the value is stored. You can think of a variable as a container that can hold different types of data like numbers, strings, arrays, objects, and more.
To declare a variable in JavaScript, you can use the var
, let
, or const
keywords. Here are some examples:
JavaScript
// Using the var keyword
var age = 25;
var name = 'John';
// Using the let keyword
let x = 10;
let y = 20;
// Using the const keyword
const PI = 3.1416;
const URL = 'https://www.example.com';
In the above examples, age
, name
, x
, and y
are variables that store numeric and string values, while PI
and URL
are variables that store constant values that cannot be changed later.