Skip to content

JS Functions

Syntax

A function in JavaScript is a reusable block of code defined with the function keyword, which can take parameters and return a value.

function functionName() {
// Code to execute
}
// Call function
functionName();
functionName = function() {
// Code to execute
}
// Call function
functionName();

Example

function sayHello() {
console.log('Hello World');
}
sayHello();
//Output: Hello World