Contenu du cours
Module 1 — Discovering JavaScript
What JavaScript does, where to write your code, the console and a first script.
0/4
Module 2 — Language fundamentals
Variables and types, operators and conditions, then loops.
0/4
Module 3 — Functions and interactivity
Writing functions, responding to events and manipulating the DOM.
0/4
Module 4 — Going further
Arrays and objects, an introduction to APIs with fetch, and best practice.
0/4
JavaScript for beginners

A function is a reusable block of code with a name. You write it once, then call it as many times as you need.

Declaring and calling a function

function direBonjour(prenom) {
  console.log("Bonjour " + prenom);
}
direBonjour("Marie");

Here, prenom is a parameter: a piece of information the function receives in order to do its job.

Returning a value

A function can send back a result with the return keyword:

  • The result can be stored in a variable.
  • Once return runs, the function stops.
function addition(a, b) {
  return a + b;
}
let total = addition(3, 4); // 7

Functions keep code organised and avoid repetition: a change in one place takes effect everywhere the function is called.

Key takeaway: a function bundles reusable code. It takes parameters and can send back a result with return.

Prix indicatifs, convertis depuis l'euro