JavaScript Variables
In JavaScript, variables are used to store data values. Variables are containers for storing information that can be referenced and manipulated in a program. JavaScript variables can hold various types of data, including numbers, strings, objects, arrays, functions, and more.
JavaScript Variables can be declared in 4 ways:
- Automatically
- Using var
- Using let
- Using const
Using the var keyword (older way, but still works)
Example
var myVariable = "Hello, CodeLines!";
Using the let keyword (introduced in ECMAScript 2015 (ES6)):
Example
let myVariable = "Hello, CodeLines!";
Using the const keyword
(also introduced in ECMAScript 2015 (ES6)). This declares a constant variable, meaning its value cannot be reassigned: