else Keyword

The else keyword provides an alternative path when an if condition is false.
It is always attached after an if or else if block.


Syntax

if (condition) {
  // executes if condition true
} else {
  // executes if condition false
}

Examples

let লগইন = false;

যদি (লগইন) {
  কনসোল.লগ("আবার স্বাগতম!");
} নাহলে {
  কনসোল.সতর্ক("প্রথমে লগইন করুন।");
}

// জোড়-বিজোড় চেক
let সংখ্যা = 7;
যদি (সংখ্যা % 2 === 0) {
  ছাপাও("জোড় সংখ্যা");
} নাহলে {
  লিখো("বিজোড় সংখ্যা");
}

Notes

  • An else block has no condition; it runs only if all previous checks fail.
  • Use else if when you need more than two branches.
  • You can nest if + else blocks for complex logic.