| Tutorials | JavaScript |
What Are Variables in JavaScript?
Variables in JavaScript are containers that store data to be used in your code.
They allow you to store numbers, text, boolean values, lists, and much more.
Declaring a Variable
To declare a variable in JavaScript, you can use the keywords var, let, or const.
Example:
let name = "Juan";
const PI = 3.1416;
var age = 25;
Common Data Types
- String →
"Hello world" - Number →
42 - Boolean →
trueorfalse - Array →
[1, 2, 3] - Object →
{ name: "Ana", age: 30 }
Practical Example
let user = "Carlos";
let age = 28;
console.log("The user is " + user + " and is " + age + " years old.");
With variables, you can handle dynamic data and start creating more useful programs.