LESSON 27 OF 50

Declare and call a function

Group behavior in a reusable function.

Official sourceECMAScript — function definitionsReviewed: 2026-08-26
STEP 1 · LEARN

How it works

A function declaration binds a name to a statement body. The body runs when the function is called by its name followed by parentheses.

Correct example
function greet() {
  console.log('Salut!');
}

greet();

The declaration defines the behavior; greet() executes it once.

Common mistake
function greet() { console.log('Salut!'); }

The function is defined, but without a call its body does not run and there is no output.

STEP 2 · APPLY

Your exercise

Declare a greet function that prints “Salut!”, then call it once.

STEP 3 · RUN

Write and run the code

script.jsJAVASCRIPT
Isolated consoleisolated
Preparing the runtime…
Run the code to see the result.
The draft stays only in this browser.Isolated QuickJS · no DOM, session or network
STEP 4 · CHECK

What needs to pass

0%not checked
  • greet is declared as a function and contains console.log.
  • The output is exactly Salut!.
  • The function runs without an error.
Explain the solution logic

The function name separates defining the behavior from the moment it executes.