JavaScript if else statement makes it easy to execute code based on different conditions. This tutorial will help you learn all you need to know about if else statement. You will learn how to use if
, else
, else if
and nested if else. You will also learn about ternary operator and much more.
JavaScript if else statement makes it very easy to execute your code if specific conditions is truthy. Its syntax is just as easy. It is composed of three parts. The first part is if
keyword. You use this keyword to tell JavaScript that you are about to create an if else statement.
The second part is a condition you want to test for. Condition is wrapped with parentheses and it follows the if
keyword. This can condition can range from very simple to very complex expressions. The only thing that matters is if the result of that expression is boolean, either true
or false
.
The third part is a block of code you want to execute. This block of code is surrounded by curly brackets. It follows right after the condition. Remember that this block of code will be executed only if the condition evaluates to true
, is truthy. If it evaluates to false
, it is falsy, the block of code will not be executed.
#javascript #web development #programming