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

Looping Array Javascript

Date : 28 Dec 2018, Category : JavaScript, Create By : admin

Looping adalah sebuah metode perulangan dimana bisanya perulangan tersebut akan menghasilakan sebuah data berurutan, misalkan looping angka numerik 1 sampai dengan 10 maka looping akan mencetak 1 2 3 4 .....

Membuat Format Rupiah Di Javascript

Date : 17 Aug 2018, Category : JavaScript, Create By : admin

Selamat datang di gudang ilmu aplikasi, sebelumnya kita telah membahas cara membuat format rupiah di PHP, kali ini kami akan membahas bagainama cara membuat format rupiah pada javascript. jika di .....

Create Inner Join Query In Mysql Database

Date : 14 Feb 2023, Category : Database, Create By : admin

In MySQL, you can use the INNER JOIN clause to combine data from two or more tables based on a common column. Here's the basic syntax: SELECT column_name(s)FROM table1INNER JOIN table2 .....