Chapter 315m
JavaScript Functions
Reusable blocks of code.
This content is not yet available in si. Showing English version.
View in English →Functions
A function is a reusable block of code.
Declaration
js
function greet(name) {
return "Hello, " + name;
}
greet("Aarav"); // "Hello, Aarav"Arrow Function (modern)
js
const greet = (name) => "Hello, " + name;Example
javascript// Functions in JavaScript
function add(a, b) {
return a + b;
}
const multiply = (a, b) => a * b;
console.log("Sum:", add(5, 3));
console.log("Product:", multiply(5, 3));