- Tutorials
- JavaScript Tutorial
- JavaScript Conditions
JavaScript Conditions
5 lessonsAbout 30 minutesBeginner
This part of the JavaScript Tutorial runs from JavaScript if Statement through to JavaScript Ternary Operator. There are 5 lessons here, and working through them takes about 30 minutes at a steady pace.
It follows on from JavaScript Statement & Expression, so finish that first if you have not already — the examples below assume you are comfortable with it.
Each lesson below says what it covers before you open it. Read them in order the first time; afterwards this page works as a index you can jump back into when you need to check one thing.
- 1JavaScript if StatementThe JavaScript if statement is used to run a block of code only when a condition is true.
- 2JavaScript if else StatementThe JavaScript if else statement is used when you want to run one block of code if a condition is true, and another block of code if the condition is false.
- 3JavaScript else if StatementThe JavaScript else if statement is used when you need to check multiple conditions.
- 4JavaScript switch StatementThe JavaScript switch statement is used to perform different actions based on different values.
- 5JavaScript Ternary OperatorThe ternary operator is a short way to choose between two values.
