Learn to Code
All tracks
Learn to Code

Free lessons from scratch to pro — every language, databases and DevOps.

AboutContactPrivacy PolicyTerms of Use

Your progress is saved in this browser. © 2026 Learn to Code

JS
JavaScript
0/12 completed
Beginner
What is JavaScript?Variables and data typesOperators and expressionsMaking decisions: if and switchLoops
Intermediate
FunctionsArrays and array methodsObjects
Advanced
Scope and closuresClasses and OOPPromises and async/await
Pro
The event loop
Tracks / JavaScript / Beginner

Operators and expressions

An expression is any piece of code that produces a value, like 2 + 3 or age >= 18. Operators are the symbols that combine values.

Arithmetic

JavaScript · editable

The remainder operator % is surprisingly useful. For example, n % 2 === 0 tells you whether n is even.

Shortcuts

JavaScript · editable

Comparison

Comparisons produce a boolean (true or false).

JavaScript · editable

Always use === and !==. The loose versions == and != convert types behind your back, which causes confusing bugs.

Logical operators

Operator Meaning Example
&& AND: both must be true age >= 18 && hasTicket
|| OR: at least one is true isAdmin || isOwner
! NOT: flips true/false !isLoggedIn
JavaScript · editable

Truthy and falsy

In a true/false situation, JavaScript treats some values as false. These are the falsy values: false, 0, '' (an empty string), null, undefined and NaN. Everything else is truthy, including '0', [] and {}.

JavaScript · editable

Default values with ?? and ||

JavaScript · editable

Operator precedence

Multiplication happens before addition, just like in maths. Use brackets to be explicit.

JavaScript · editable

Practice

A shop gives a 10% discount when the total is over 100. Given price and qty, print the final amount. Then print whether qty is even.

JavaScript · editable
✎ Check your understanding

1.What is 17 % 5?

2.What does 0 ?? 10 return?

← Variables and data types