How To Use If In Javascript

Tanggal : 14 Feb 2023, Category : JavaScript, Create By : admin

In JavaScript, you can use the "if" statement to execute code based on a condition. The basic syntax is:

if (condition) {
// code to execute if the condition is true
}
 

Here's an example:

let age = 25;

if (age >= 18) {
console.log("You are an adult.");
}
 

In this example, the code inside the curly braces will only be executed if the condition inside the parentheses (age is greater than or equal to 18) is true. If the condition is false, the code inside the curly braces will be skipped.

You can also use "else" to specify code to execute if the condition is false, like this:

let age = 15;

if (age >= 18) {
console.log("You are an adult.");
} else {
console.log("You are not an adult.");
}
 

In this example, since age is less than 18, the code inside the "else" block will be executed, and "You are not an adult." will be logged to the console.

 


Keyword:
  • How To Use If In Javascript

Artikel Lain

Type Casting In Java

Date : 15 Feb 2023, Category : Pemprograman Website, Create By : admin

Type casting in Java is the process of converting a variable of one data type into another data type. There are two types of type casting in Java: implicit casting .....

Apa Itu Website ?

Date : 07 Jul 2018, Category : Pemprograman Website, Create By : admin

Selmat datang di gudang ilmu aplikasi, kali ini kita akan membahas apa itu wabsite, fungsi website dan jenis wesbite. Website atau sering kita sebut situs adalah kumpulan halaman - halaman .....

Here's A Basic Example Of How To Use Simpy In Python

Date : 13 Feb 2023, Category : Tutorial, Create By : admin

SimPy is a process-based discrete-event simulation framework based on Python. It allows you to model real-world systems and their interactions, and to analyze the behavior of those systems over time. Here's .....