javascript / beginner
Snippet
Conditional Logic with If and Else
The 'if' statement executes a block of code if a condition is true. The 'else' block runs if that same condition is false.
snippet.js
1
2
3
4
5
6
const temp = 30;if (temp > 25) {console.log("It is hot!");} else {console.log("It is cool.");}
nodejs
Breakdown
1
if (temp > 25) {
Checks if the temperature is greater than 25.
2
console.log("It is hot!");
This code runs only if the condition is true.
3
} else {
Starts the alternative block if the condition fails.