1. "Hello, World!" – Your First JavaScript Program
Slug: hello-world-javascript
JavaScript is like a friendly neighbor who greets you with a warm "Hello, World!" Let's write our first program:
console.log("Hello, World!");
2. "Variables: The Building Blocks"
Slug: javascript-variables
Variables store information. Imagine them as tiny treasure chests. Declare one like this:
let favoriteColor = "blue";
3. "Functions: The Superpowers"
Slug: javascript-functions
Functions are like magical spells. They take input, perform actions, and return results. Here's a simple function:
function add(a, b) {
return a + b;
}
const result = add(5, 3); // Result: 8
4. "Conditionals: Choose Your Adventure"
Slug: javascript-conditionals
Conditionals help your program make decisions. It's like choosing between ice cream flavors:
const age = 18;
if (age >= 18) {
console.log("You can vote!");
} else {
console.log("Wait a few more years.");
}
5. "Loops: The Dance Moves"
Slug: javascript-loops
Loops repeat actions. Picture a dance floor – you keep dancing until the music stops:
for (let i = 1; i <= 5; i++) {
console.log(`Step ${i}`);
}
6. "DOM Manipulation: Decorating Your Webpage"
Slug: javascript-dom-manipulation
The Document Object Model (DOM) lets you change your webpage dynamically. Imagine redecorating your room:
const heading = document.querySelector("h1");
heading.textContent = "Welcome to My Awesome Website!";
And there you have it! JavaScript – the language that brings interactivity and magic to the web. 🌟✨ Feel free to explore more, experiment, and create your own enchanting web experiences! 🚀🔮
Top comments (0)