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

How To Overcome Insomnia And Improve Sleep.

Date : 11 Feb 2023, Category : Health, Create By : admin

Insomnia is a common sleep problem experienced by many people. There are many factors that can cause insomnia, such as stress, depression, bad habits, and alcohol consumption. However, there are .....

Mengenal Fungsi Echo Php

Date : 27 Dec 2018, Category : Tutorial, Create By : admin

Bagi kalian yang sudah masuk kedalam dunia pemprograman php pasti tidak asing lagi dan bahkan sering sekali menggunakan fungsi echo ini, akan tetapi bagi yang baru terjun di dunai pemprograman .....

Membuat Validasi Input Data Email Dan Url Website Php

Date : 25 Jul 2018, Category : Tutorial, Create By : admin

Selamat datang di website gudangilmuaplikasi.com, kali ini kami akan membahas tentang membuat validasi input data email dan url website php menggunakan filter_var dan preg_match, pada dasarnya tutorial validasi yang kami sampaikan hanya dasar .....