{
  "id": 3869016,
  "title": "Javascript If-else Statement",
  "url": "https://urgent.news/2026/08/28/javascript-if-else-statement",
  "topic": "tech",
  "section": "Tech",
  "published": "2026-08-28T01:45:00.000Z",
  "source": {
    "name": "Dev.to",
    "slug": "dev-to",
    "url": "https://dev.to/jaisurya/javascript-if-else-statement-nj2"
  },
  "original_language": "en",
  "account": "The JavaScript if-else statement is employed to execute code based on whether a condition is true or false. There exist three variations of the if statement in JavaScript: 1. if statement, 2. if else statement, and 3. if else if statement.\n\nThe if statement is evaluated only if the expression is true. For instance, in the following code snippet, if variable 'a' is greater than 10, then it will display the message \"value of a is greater than 10\".\n\n```javascript\nlet a = 20;\nif (a > 10) {\ndocument.write(\"value of a is greater than 10\");\n}\n```\n\nThe output of this code would be: \"value of a is greater than 10\".\n\nThe if else statement evaluates the content depending on whether the condition is true or false. For example, in the code below, if 'a' is an even number, it will print \"a is even number\". However, if 'a' is an odd number, the script will print \"a is odd number\".\n\n```javascript\nlet a = 20;\nif (a % 2 == 0) {\ndocument.write(\"a is even number\");\n} else {\ndocument.write(\"a is odd number\");\n}\n```\n\nThe output would be: \"a is even number\".\n\nLastly, the if else if statement evaluates the content based on several expressions. It will display the result of the first true expression. If none of the expressions are true, it will execute the code within the else block. In the following example, if 'a' is equal to 20, it will print \"a is equal to 20\".\n\n```javascript\nlet a = 20;\nif (a == 10) {\ndocument.write(\"a is equal to 10\");\n} else if (a == 15) {\ndocument.write(\"a is equal to 15\");\n} else if (a == 20) {\ndocument.write(\"a is equal to 20\");\n} else {\ndocument.write(\"a is not equal to 10, 15 or 20\");\n}\n```\n\nThe output of this code would be: \"a is equal to 20\".",
  "summary": "The JavaScript if-else statement is used to execute the code whether condition is true or false. There are three forms of if statement in JavaScript. 1.if statement 2.if else statement 3.if else if statement 1.JavaScript if statement It evaluate the content only if expression is true. //Syntax if ( expression ){ //content to be evaluated } //Example code < script > let a = 20 ; if ( a > 10 ){…",
  "key_points": [],
  "editors_take": null,
  "illustration": null,
  "coverage": {
    "outlets": 1,
    "also_reported_by": []
  },
  "ai_generated": true,
  "disclaimer": "Summaries, key points and the editor’s take are written by software from other outlets’ reporting and may contain errors — always check the linked original."
}