Introduction
JavaScript powers the modern web. It lets you create interactive experiences, manipulate the DOM, and communicate with servers.
Variables
let name = "Alice";
const PI = 3.14159;
var old = true; // avoid var in modern code
Functions
function greet(person) {
return `Hello, ${person}!`;
}
const add = (a, b) => a + b;
Asynchronous JavaScript
async function fetchData(url) {
const response = await fetch(url);
const data = await response.json();
return data;
}
DOM Manipulation
document.getElementById('myBtn').addEventListener('click', () => {
alert('Button clicked!');
});