JavaScript Variables
JavaScriptVariables store data. JavaScript has 3 ways to declare variables:
let— can be changed later (use this most!)const— cannot be changed (use for constants)var— old way, avoid in modern code
Data Types
JavaScript automatically detects the type: string, number, boolean, array, object.
Example — JAVASCRIPT
// String
let name = "Priya";
// Number
let age = 20;
// Boolean
const isStudent = true;
// Array
let skills = ["HTML", "CSS", "JS"];
// Object
let person = {
name: "Rahul",
age: 22,
city: "Mumbai"
};
console.log(name); // Priya
console.log(skills[0]); // HTML
console.log(person.city); // Mumbai
Result
▶ "Priya"
▶ "HTML"
▶ "Mumbai"
▶ "HTML"
▶ "Mumbai"