JavaScript is a scripting language used to add interactivity to HTML documents.
const arr = [1, 2, 3];
console.log(arr); // Output: [1, 2, 3]
const now = new Date();
console.log(now); // Output: Wednesday, November 26, 2023 12:00:00 PM EST
console.log(Math.sqrt(25)); // Output: 5
console.log(Math.max(5, 10, 3)); // Output: 10
JavaScript provides event handlers for various types of events, including:
JavaScript uses function calls and returns to execute code sequentially.
function greet(name) {
return `Hello, ${name}!`;
}
console.log(greet("Alice")); // Output: Hello, Alice!
JavaScript supports asynchronous programming using async/await syntax.
async function fetchData() {
try {
const result = await fetch("/data");
console.log(result);
} catch (error) {
console.error(error);
}
}
fetchData(); // Output: Data from API
JavaScript is a powerful language for creating dynamic web applications and enhancing user interaction.