
JavaScript Variables and Data Types (Beginner Guide)
1. What Are Variables? Think of a variable like a box that stores information. Imagine you have labeled boxes: One box stores your name Another stores your age Another stores whether you are a student In programming, we store information inside variables so the computer can use it later. Example: let name = " Rahul " ; let age = 18 ; Here: name stores "Rahul" age stores 18 So a variable is simply a container for storing data. 2. How to Declare Variables in JavaScript In JavaScript, we can create variables using three keywords: var let const Using var var city = " Delhi " ; var was used in older JavaScript versions. It still works but is less recommended today. Using let let age = 20 ; let is commonly used when the value may change later. Example: let score = 10 ; score = 15 ; Now score becomes 15 . Using const const country = " India " ; const means constant , which means the value cannot be changed later. Example: const pi = 3.14 ; Trying to change it will cause an error. 3. Primitive
Continue reading on Dev.to
Opens in a new tab




