Control Flow in JavaScript: If, Else, and Switch Explained
What does control flow means in programming
Control flow means a particular code section to run based on a condition. That is called control flow in programming. "Controlled way mein yani ki condition ke basis pe code execution hona."
if statement
It simply takes a condition and if that condition is true, the code inside its scope will be executed and if the condition is not satisfied, then it won't run and that particular section will be skipped.
To Be More Precise in logical terms : Simply check if the condition is zero or non-zero.
Note : If consective if-blocks are present all if blocks are checked.
if-else
It is same as above but the only difference is that either of the code block that is either of if or else will run. Not Both will run.
else-if
All if and else-if blocks will run and whichever condition is satisfied that block will run then all else-if blocks and else blocks below it will be skipped.
Swich-case
Think of it like you are switching (changing) a variable to multiple cases and whichever case is satisfied will be executed. And if nothing satisfies, then default case will be executed.
Like in above example -> status is variable and it could have multiple values like 200, 404, 500. These are actually response status code nothing else.
Now, there is a break keyword which prevents further codes to be executed. If break is not present, then next cases will be executed unless it finds a break.
Presented by -
Nand Kishore

