1๏ธโฃ Variables โ Storing Data
JavaScript uses
let, const, and var to declare variables.let name = "John"; // can change later
const age = 25; // constant, can't be changed
var city = "Delhi"; // older syntax, avoid using it
โถ๏ธ Tip: Use
let for variables that may change and const for fixed values.2๏ธโฃ Functions โ Reusable Blocks of Code
function greet(user) {
return "Hello " + user;
}
console.log(greet("Alice")); // Output: Hello Alice
โถ๏ธ Use functions to avoid repeating the same code.
3๏ธโฃ Arrays โ Lists of Values
let fruits = ["apple", "banana", "mango"];
console.log(fruits[0]); // Output: apple
console.log(fruits.length); // Output: 3
โถ๏ธ Arrays are used to store multiple items in one variable.
4๏ธโฃ Loops โ Repeating Code
for (let i = 0; i < 3; i++) {
console.log("Hello");
}
let colors = ["red", "green", "blue"];
for (let color of colors) {
console.log(color);
}
โถ๏ธ Loops help you run the same code multiple times.
5๏ธโฃ Conditions โ Making Decisions
let score = 85;
if (score >= 90) {
console.log("Excellent");
} else if (score >= 70) {
console.log("Good");
} else {
console.log("Needs Improvement");
}
โถ๏ธ Use
if, else if, and else to control flow based on logic.๐ฏ Practice Tasks:
โข Write a function to check if a number is even or odd
โข Create an array of 5 names and print each using a loop
โข Write a condition to check if a user is an adult (age โฅ 18)
๐ฌ Tap โค๏ธ for more!