Javascript is a versatile programming language used for creating dynamic and interactive web content.
Functions are like mini-machines: you give them input, and they give you output. They help organize your code into chunks you can reuse.
function greet(person) {
alert("Hello, " + person + "!");
}
greet("Sam");
Here, greet
is a function that says hello to anyone you want!
JavaScript can react to things that happen, like clicks or key presses. These are called events.
document.getElementById("myButton").onclick = function() {
alert("Button clicked!");
};
This code makes a button alert a message when clicked.
Making a character jump when you press a key in a game
Calculating your age from your birth year
Functions organize your code, and events let your website respond to users.