An overview of Javascript fundementals
Conditional statements are used to perform different actions based on different conditions. Very often when you write code, you want to perform different actions for different decisions. You can use conditional statements in your code to do this. In JavaScript we have the following conditional statements:
if
to specify a block of code to be executed, if a specified condition is trueelse if
to specify a new condition to test, if the first condition is falseelse
to specify a block of code to be executed, if all preceding conditions are falseif (greeting === "hello" && question === "What's the time?") { //this block of code is executed if the 1st condition is true console.log("It is 10 o'clock"); } else if (greeting === "Hello" || question == "What is the weather like tomorrow?") { //this block of code is executed if the 1st condition is false and the 2nd condtion is true console.log("It will be suuny tomorrow."); } else { //this block of code is executed if the 1st and 2nd condition are false console.log("I don't understand the question.") }
Comparison operators
==
equal to===
equal value and equal type!=
not equal!==
not equal value or not equal type>
greater than<
less than>=
greater than or equal to<=
less than or equal toLogical operators
&&
and||
or!
notComplete the statement to print "Hello World!" if num1 is greater than num 2.
let num1 = 20; let num2 = 15; if ( ) { console.log("Hello World!") } try Again!