What are the Conditional Statements in #JavaScript?

Thread🧵
🟡What is a Conditional Statement?

Very often when you write code, you want to perform different actions for different decisions.

Conditional statements control behavior in JavaScript and determine whether or not pieces of code can run.
🟡We use "if" to specify a block of code to be executed, if a specified condition is true.

🟡We use "else" to specify a block of code to be executed, if the same condition is false

🟡We use "else if" to specify a new condition to test, if the first condition is false.
🟡1) If Statement:

As mentioned before, the if statement only runs if the condition enclosed in parentheses () is true.

Example:
In the above example, the output will be "if block".

💡(8 > 4) is the condition to test, which in this case it is true.
The part contained inside curly braces {} is the block of code to run.
Because the condition passes, the variable outcome is assigned the value "if block".
🟡2) Else Statement:

You can extend an if statement with an else statement, which adds another block to run when the if conditional doesn’t pass.
In the example above, if the hour is less than 18, the output will be "Good day", otherwise it will be"Good evening".
🟡3) Else If Statement:

This statement is to specify a new condition if the first condition is false.
In the above example, we're saying that - If time is less than 10:00, create a "Good morning" greeting, if not, but time is less than 20:00, create a "Good day" greeting, otherwise create a "Good evening".
That's all👊

If you’re a beginner and found this short thread useful, please consider following @salimelliye and retweeting the first tweet.

#CodeNewbie

• • •

Missing some Tweet in this thread? You can try to force a refresh
 

Keep Current with e͒.salim💻

e͒.salim💻 Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @salimelliye

6 Jan
Planning to start with #JavaScript in 2022?
This short thread will help you!🧵
Start with beginners projects:

🟡 Quiz Game
sitepoint.com/simple-javascr…

🟡Digital clock
geeksforgeeks.org/how-to-design-…

🟡Photo gallery
data-flair.training/blogs/javascri…

🟡To-do List
data-flair.training/blogs/javascri…

🟡Rock Paper Scissors
mikkegoes.com/javascript-pro…
Read 6 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Too expensive? Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal

Or Donate anonymously using crypto!

Ethereum

0xfe58350B80634f60Fa6Dc149a72b4DFbc17D341E copy

Bitcoin

3ATGMxNzCUFzxpMCHL5sWSt4DVtS8UqXpi copy

Thank you for your support!

Follow Us on Twitter!

:(