if Statement

noun

say it: “IF STAYT-ment” /ɪf ˈsteɪtmənt/

Code that runs a block only when its condition is true, as in if (total > 25) { ... }.

What does if Statement do in JavaScript?

if Statement — Runs a block of code only when a condition is true.

if (stock > 0) {
    status = "Available";
} else {
    status = "Sold out";
}

In a sentence

  • “My if statement prints "Free delivery!" only when the order is over $25.”

Level: Novice · More JavaScript terms at this level

Updated

In other subjects