JavaScript is a scripting language used to make websites interactive โ handling user actions, animations, and dynamic content.
1๏ธโฃ Variables & Data Types
Use
let for reassignable variables, const for constants (avoid var due to scoping issues).let name = "Alex";
const age = 25;
Data Types: string, number, boolean, object, array, null, undefined.
2๏ธโฃ Functions
Reusable blocks of code.
function greet(user) {
return `Hello, ${user}`;
}Or use arrow functions for concise syntax:
const greet = (user) => `Hello, ${user}`;3๏ธโฃ Conditionals
if (age > 18) {
console.log("Adult");
} else {
console.log("Minor");
}4๏ธโฃ Loops
for (let i = 0; i < 5; i++) {
console.log(i);
}5๏ธโฃ Arrays & Objects
let fruits = ["apple", "banana"];
let person = { name: "John", age: 30 };
6๏ธโฃ DOM Manipulation
document.getElementById("demo").textContent = "Updated!";7๏ธโฃ Event Listeners
button.addEventListener("click", () => alert("Clicked!"));8๏ธโฃ Fetch API (Async)
fetch("https://api.example.com").then(res => res.json()).then(data => console.log(data));9๏ธโฃ ES6 Features
โฆ
let, constโฆ Arrow functions
โฆ Template literals:
Hello ${name}โฆ Destructuring:
const { name } = person;โฆ Spread/rest operators:
...fruits๐ก Tip: Practice JS in browser console or use online editors like JSFiddle / CodePen.
๐ฌ Tap โค๏ธ for more!