JavaScript (Conditionals)

JavaScript (Conditionals)

Conditionals ?

What are Conditionals ?

What are they used for ?

Conditionals ? First of all, before we talk about what conditionals let's break it down to the word (condition).

What is a Condition ?

A condition is to have a significant influence on or determine (the manner or outcome of something).

What are Conditionals ?

Conditional control behavior in JavaScript and determine whether or not pieces of code can run. There are different types of conditionals in JavaScript including: “If” statements. Conditionals are expressions that evaluate to either true or false.

What are they used for ?

They tell you whether the code you put in is true or it is false.

Examples :

let number = 9;
 if(number === 5){
     console.log(5)

 }
 else{
     console.log('number is not equal to 5')
 }

basically this code says let the number equal to 9, then it says if the number is 5 ( they use 3 equal to, to show that you know and sure it is equal to this) console.log 5 (print 5) else print number is not equal to 5.

this is going to print

number is not equal to 5

Why are Conditionals important ?

Conditional statements help mathematicians and computer programmers make decisions based on the state of a situation.

Watch this video to understand more on Conditionals :

youtube.com/watch?v=dJYIRcsdHWg