← JavaScript tutorial

JavaScript

Operators

Arithmetic operators (+ - * / %) do math. Comparison operators (=== !== > <) compare two values and produce a boolean.

Example: why === and not ==

console_check_1 = (0 == "");    // true, surprising!
console_check_2 = (0 === "");   // false, no automatic conversion

const score = 85;
const passed = score >= 50 && score <= 100;
document.getElementById("output").textContent = "Passed: " + passed;

== ("loose equality") silently converts values to a matching type before comparing them, which produces surprising results like the first line above. === ("strict equality") skips that conversion entirely, it compares both value and type, which is almost always what you actually mean. Use === and !== by default; reach for == only if you can explain exactly why you need the automatic conversion.

Combining conditions with logical operators

&& ("and") requires both sides to be true; || ("or") requires at least one; ! negates a single value. The example above uses && to check that a score is both at least 50 and at most 100.

Try it yourself
Ready to go further?

These free tutorials are a preview, our Frontend Development cohort covers it in depth, with a real project and a cohort alongside you. Closes Nov 30

Enroll in Frontend Development

Cookie preferences

Choose what you're comfortable with. You can change this any time from the footer.

Don't miss out

Ready to build something real?

Create a free account to enroll in a track, and get notified the moment a cohort opens.

Create free account