Mahir freeCodeCamp • top-learn-data-types-and-conditionals

Learn Data Types and Conditionals Lesson H

Ringkasan Pelajaran

In any programming language, you need to compare values to make decisions. For example, if the weather is sunny, you will go out, otherwise you will stay at home. Another example would be to see if...

In any programming language, you need to compare values to make decisions. For example, if the weather is sunny, you will go out, otherwise you will stay at home. Another example would be to see if a user has enough points to level up in a game.

The if-else conditional statement is used to make decisions in JavaScript. It is often used with comparison operators to compare values and make decisions based on the results.

An example of an if statement is:

let x = 5;

if (x > 3) {
  console.log("x is greater than 3");
} else {
  console.log("x is less than or equal to 3");
}

In this example, the x variable is compared to the number 3 using the > operator. If x is greater than 3, the first block of code will be executed. Otherwise, the second block of code will be executed.