𝗝𝗮𝘃𝗮𝗦𝗰𝗿𝗶𝗽𝘁 𝗖𝗼𝗻𝗱𝗶𝘁𝗶𝗼𝗻𝗮𝗹 𝗕𝗿𝗮𝗻𝗰𝗵𝗶𝗻𝗴

Your code needs to make decisions. Conditional statements control the flow of your program. They run specific code blocks based on a true or false result.

Use these three main types:

  • if: Runs code only when a condition is true.
  • if-else: Runs one block if true and another if false.
  • else if: Checks multiple conditions in order.

You also need to know Truthy and Falsy values. JavaScript evaluates every value as a boolean.

Falsy values are always false:

  • false
  • 0
  • empty strings
  • null
  • undefined
  • NaN

Truthy values are everything else:

  • Non-zero numbers
  • Filled strings
  • Objects
  • Arrays

Source: https://dev.to/karthick_k_983555db6df3/conditional-branching-if--4lb9