If
En basit koşul ifadesi "if" ifadesidir ve sözdizimi (syntax) if (koşul) { bunu yap ... } şeklindedir. Koşul, süslü parantezlerin içindeki kodun yürütülmesi için doğru (true) olmalıdır. Örneğin, aşağıda açıklandığı gibi bir dizeyi test edebilir ve değerine bağlı olarak başka bir dizenin değerini ayarlayabilirsiniz.
let country = "France";
let weather;
let food;
let currency;
if (country === "England") {
  weather = "horrible";
  food = "filling";
  currency = "pound sterling";
}
if (country === "France") {
  weather = "nice";
  food = "stunning, but hardly ever vegetarian";
  currency = "funny, small and colourful";
}
if (country === "Germany") {
  weather = "average";
  food = "wurst thing ever";
  currency = "funny, small and colourful";
}
let message =
  "this is " +
  country +
  ", the weather is " +
  weather +
  ", the food is " +
  food +
  " and the " +
  "currency is " +
  currency;
console.log(message);
// 'this is France, the weather is nice, the food is stunning, but hardly ever vegetarian and the currency is funny, small and colourful'
Koşullar aynı zamanda iç içe de olabilir.