Chapter 06
JavaScript Variables
A variable is a named storage location used to store and work with data in a program.
01 • Learn
What is JavaScript Variables?
- Variables can store text, numbers, Boolean values, objects, and other data.
- A variable has a name that allows the stored value to be accessed later.
- Modern JavaScript commonly uses let and const for variable declarations.
- Meaningful variable names make programs easier to understand.
02 • Syntax
Syntax
let variableName = value; let studentName = 'Rahul'; let marks = 85;
03 • Example
Example
Try understanding this code before running it.
let studentName = 'Rahul'; let age = 20; let course = 'Web Development'; console.log(studentName); console.log(age); console.log(course);
04 • Remember
Important Points
- Variable names can begin with a letter, underscore, or dollar sign.
- Variable names cannot contain spaces.
- JavaScript variable names are case-sensitive.
- Use meaningful names such as studentName and totalMarks.
05 • Avoid
Common Mistakes
- Using spaces in variable names.
- Using a reserved keyword as a variable name.
- Using confusing or meaningless variable names.
06 • Practical
Real-World Use
Variables are used to store student marks, product prices, user names, login status, shopping cart data, and much more.
07 • Practice
Practice Exercise
Practice: Variables
Create variables named studentName, studentAge, and courseName. Display all three values in the console.
Ready to write code?
Open the JavaScript editor and run your code with live output.