Track: JavaScript Basics
Lesson: JS-01 / JS-10
🎯 Lesson Goal
By the end of this lesson, you will understand how to store data in JavaScript using variables and identify different data types used in real-world programming.
📌 Prerequisites
- Basic computer knowledge
- No prior programming experience required
📘 What is JavaScript?
JavaScript is a programming language used to make web pages interactive.
It allows us to:
- Respond to user actions
- Change content dynamically
- Build web and server-side applications
📘 What are Variables?
A variable is a container used to store data in memory.
Think of it as a labeled box where you keep information for later use.
Example:
let name = "Kavita";
let age = 25;
Here:
namestores textagestores a number
🧩 Declaring Variables in JavaScript
JavaScript provides three keywords to declare variables:
1️⃣ var (old way – avoid)
var city = "Delhi";
Problems with var:
- Function-scoped
- Can cause bugs
- Not recommended in modern JS
2️⃣ let (recommended)
let course = "JavaScript";
course = "MERN Stack";
- Block-scoped
- Value can be changed
3️⃣ const (constant value)
const institute = "Programming Empire";
- Block-scoped
- Value cannot be changed
📘 JavaScript Data Types
Data types specify what kind of data a variable can store.
🔢 1. Number
Stores numeric values (integers and decimals).
let marks = 85;
let price = 199.99;
🔤 2. String
Stores text data (written inside quotes).
let studentName = "Aman";
let city = 'Delhi';
✔️ 3. Boolean
Stores true or false.
let isLoggedIn = true;
let hasPaid = false;
❓ 4. Undefined
A variable declared but not assigned a value.
let result;
console.log(result); // undefined
🚫 5. Null
Represents no value intentionally.
let response = null;
📦 6. Object
Stores multiple values in a single variable.
let student = {
name: "Riya",
age: 22,
course: "BCA"
};
📋 7. Array
Stores multiple values in an ordered list.
let subjects = ["HTML", "CSS", "JavaScript"];
🔍 Using typeof Operator
To check the data type of a variable:
typeof 10; // number
typeof "Hello"; // string
typeof true; // boolean
typeof {}; // object
⚠️ Common Mistakes
- Using
varinstead ofletorconst - Forgetting quotes for strings
- Trying to change a
constvalue - Confusing
nullwithundefined
🧠 Practice Tasks
- Declare a variable for your name using
let - Declare a constant for your institute name
- Create an array of 5 programming languages
- Create an object storing student details
- Use
typeofto check each variable
📝 Summary
- Variables store data in memory
letandconstare preferred overvar- JavaScript supports multiple data types
- Objects and arrays store complex data
typeofhelps identify data types
➡️ Next Lesson
JavaScript Operators and Expressions (JS-02)
🏅 Quiz & Badge
Quiz and badges will be enabled soon.