Featured
- Get link
- X
- Other Apps
๐งฎ Day 3 — Operators & Expressions in JavaScript
๐งฎ Day 3 — Operators & Expressions in JavaScript
Welcome to Day 3 ๐! Now that you can create variables and work with data, let’s explore how to **perform operations and make logic happen** in your code. Operators are what make JavaScript dynamic — they let you calculate, compare, and assign values, while expressions combine these operators to produce meaningful results.
⚙️ 1️⃣ What Are Operators?
Operators are **symbols** used to perform operations on values and variables.
Example: +, -, *, =, ==, etc.
๐ข 2️⃣ Types of Operators
Arithmetic Operators
Used for mathematical calculations:
let a = 10, b = 5; console.log(a + b); // 15 console.log(a - b); // 5 console.log(a * b); // 50 console.log(a / b); // 2 console.log(a % b); // 0 console.log(a ** 2); // 100
Assignment Operators
Used to assign values to variables.
let x = 10; x += 5; // x = x + 5 x -= 2; // x = x - 2 x *= 3; // x = x * 3 console.log(x); // 39
Comparison Operators
Used to compare two values and return true or false.
let a = 10, b = "10"; console.log(a == b); // true (value only) console.log(a === b); // false (value + type) console.log(a != b); // false console.log(a > 5); // true console.log(a <= 5); // false
Logical Operators
Used to combine conditions.
&&— AND (both must be true)||— OR (at least one true)!— NOT (reverses result)
let age = 20; console.log(age > 18 && age < 25); // true console.log(age < 18 || age > 25); // false console.log(!(age < 18)); // true
String Operators
Used to join strings.
let first = "Rahul"; let last = "Naidu"; console.log(first + " " + last);
๐งฎ 3️⃣ Expressions
An expression is any valid combination of variables, operators, and values that returns a result.
let result = (10 + 5) * 2; console.log(result); // 30
๐ง 4️⃣ Practice Task
- Create two numbers and find their sum, difference, and product.
- Compare two variables using both
==and===. - Use logical operators to check age eligibility.
๐ฏ Summary
Operators and expressions are the heart of computation in JavaScript. Next, you’ll learn how to **control the flow of your program** using conditional statements — if, else, and switch.
Popular Posts
๐ Day 27: Bootstrap Mini Project – Responsive Portfolio Page
- Get link
- X
- Other Apps
๐จ Day 2: Headings, Paragraphs & Text Formatting
- Get link
- X
- Other Apps
Comments
Post a Comment