Understanding if else statements in JavaScript

What is if else in JavaScript? In JavaScript, the if else statement is used to make decisions in your code. It allows your program to run different blocks of code depending on whether a condition is true or false. Syntax: if (condition) {  // code to run if condition is true } else {  // code to run if condition is false }  Example 1: let age = 18; if (age >= 18) {  console.log("You are an adult!"); } else {  console.log("You are a minor!"); } Output: You are an adult! Example 2: Checking even or odd number let number = 7; if (number % 2 === 0) {  console.log("Even number"); } else {  console.log("Odd number"); } Output: Odd number #html #css #javascript #react #webDesign #wevdeveloping

  • diagram

To view or add a comment, sign in

Explore content categories