𝗖𝗼𝗻𝗱𝗶𝘁𝗶𝗼𝗻𝗮𝗹 𝗦𝘁𝗮𝘁𝗲𝗺𝗲𝗻𝘁𝘀 𝗶𝗻 𝗝𝗮𝘃𝗮𝗦𝗰𝗿𝗶𝗽𝘁

You need your code to make choices.

Conditional statements do this. They run code based on true or false results.

Use these tools:

  • if: runs code if a condition is true.
  • else: runs code if a condition is false.
  • else if: checks a new rule if the first fails.
  • switch: handles many choices.
  • ternary: a short way to write if else.

Avoid putting if statements inside each other. This makes your code hard to read. Use the AND operator instead.

Source: https://dev.to/vidhya_murali_5aabe7784bd/conditional-statements-in-javascript-49g0