JavaScript Introduction
JavaScript is a programming language that allows you to make websites interactive. It is used to control behavior, handle user input, and dynamically update content.
Variables
Variables are used to store data that can be reused throughout your program.
In JavaScript, let is used for values that may change,
while const is used for values that should remain constant.
let age = 18;
const name = "Loris Widmer";
Functions
Functions are reusable blocks of code that perform a specific task. They help keep your code organized and reduce repetition.
function greet() {
alert("Hello World");
}
Conditionals
Conditional statements allow your program to make decisions. Code inside a condition only runs if the specified condition evaluates to true.
if (age >= 18) {
console.log("Adult");
}
Button Interaction (Events)
JavaScript can react to user actions such as clicks, keyboard input, or mouse movement. These interactions are handled using events.
Counter Example
This example demonstrates how JavaScript updates values dynamically. Each button click changes a variable and updates the displayed result instantly.
0DOM Manipulation
The DOM (Document Object Model) allows JavaScript to access and modify HTML elements. This makes it possible to change text and content without reloading the page.
This text will change.