Type something to search...

JavaScript Functions

JavaScript Functions

Functions are reusable blocks of code that perform a specific task.

Declaring a Function

You can declare a function using the function keyword.

function greet(name) {
    console.log("Hello, " + name + "!");
}

Calling a Function

To execute a function, you call it by its name and pass any required arguments.

greet("Alice"); // Output: Hello, Alice!

Return Values

Functions can return a value using the return keyword.

function add(a, b) {
    return a + b;
}
let result = add(5, 3);
console.log(result); // Output: 8

Next: Arrays →