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

Html Headings And How To Use Them

Date : 15 Feb 2023, Category : HTML, Create By : admin

HTML headings are used to define the structure and hierarchy of content on a web page. There are six levels of headings in HTML, from H1 to H6, where H1 .....

Merubah Text Menjadi Angka Javascript

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

Selamat dantang kembali di gudang ilmu aplikasi, kali ini kali akan membahas fungsi javascript yang sangat berguna bagi anda yang sedang membangun aplikasi yang sering menggunakan perhitungan, fungsi parseInt digunakan untuk merubah text .....

How To Install Nginx On Debian Server

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

To install Nginx on a Debian server, you need to follow these steps: Update the package list:  sudo apt-get update Install Nginx:  sudo apt-get install nginx Start the Nginx service:  sudo systemctl start nginx Check the status .....