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 program constantly makes decisions: « if this is the case, then do that ». Those are conditions.

Useful operators

  • Arithmetic: +, -, *, /.
  • Comparison: === (equal to), !== (not equal to), >, <.
  • Logical: && (and), || (or).

The if / else structure

let age = 18;
if (age >= 18) {
  console.log("Majeur");
} else {
  console.log("Mineur");
}

The condition in brackets is evaluated: if it is true, the first block runs, otherwise the else block does. Watch out: you compare with three equals signs (===), whereas a single one (=) assigns a value.

Key takeaway: if / else lets a program respond to different situations. Compare with ===, never with a single =.

Prix indicatifs, convertis depuis l'euro