JavaScript Essentials

Learn how to make your web pages interactive and dynamic using JS.

Introduction

JavaScript is the brain of the web. It allows you to build interactive UI, handle events, and connect to APIs seamlessly.

console.log("Welcome to Developer HUB!");

Variables & Data Types

let name = "Muaaz";
const age = 18;
console.log(`${name} is ${age} years old.`);

Functions

Functions allow you to reuse logic and structure your code neatly.

function greet(user) {
  return `Hello, ${user}!`;
}

console.log(greet("Developer")); // Output: Hello, Developer!

Loops & Conditionals

Control how your code runs and responds to data.

for (let i = 1; i <= 5; i++) {
  console.log(i);
}

if (true) {
  console.log("Condition is true!");
}

DOM Manipulation

Access and modify elements dynamically in the browser.

document.querySelector("h1").textContent = "Hello, JS World!";
document.body.style.background = "#0a192f";

Fetching APIs

Interact with external data using fetch() and promises.

fetch("https://api.github.com/users/codewithmuaaz")
  .then(res => res.json())
  .then(data => console.log(data))
  .catch(err => console.error("Error:", err));