{"id":83,"date":"2026-05-01T15:13:40","date_gmt":"2026-05-01T15:13:40","guid":{"rendered":"https:\/\/gigz.pk\/javascript\/?post_type=lesson&#038;p=83"},"modified":"2026-05-01T15:13:41","modified_gmt":"2026-05-01T15:13:41","slug":"if-else-if-else","status":"publish","type":"lesson","link":"https:\/\/gigz.pk\/javascript\/?lesson=if-else-if-else","title":{"rendered":"if, else if, else"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Introduction<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Conditional statements in JavaScript allow programs to make decisions based on different conditions. They control the flow of code by executing specific blocks only when certain conditions are true. This makes applications smarter and more interactive.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Understanding if Statement<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The if statement is used to execute a block of code only when a condition is true. If the condition is false, the code inside the if block will not run.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Example<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>let age = 18;<br><br>if (age &gt;= 18) {<br>  console.log(\"You are eligible to vote\");<br>}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Understanding else Statement<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The else statement is used when you want to execute a block of code if the condition in the if statement is false.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Example<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>let age = 16;<br><br>if (age &gt;= 18) {<br>  console.log(\"You are eligible to vote\");<br>} else {<br>  console.log(\"You are not eligible to vote\");<br>}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Understanding else if Statement<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The else if statement allows you to check multiple conditions. It is useful when there are several possible outcomes.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Example<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>let marks = 75;<br><br>if (marks &gt;= 90) {<br>  console.log(\"Grade A\");<br>} else if (marks &gt;= 70) {<br>  console.log(\"Grade B\");<br>} else if (marks &gt;= 50) {<br>  console.log(\"Grade C\");<br>} else {<br>  console.log(\"Fail\");<br>}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">How Conditional Flow Works<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">JavaScript checks conditions from top to bottom<br>The first true condition will execute<br>Once a condition is true, the rest are skipped<br>The else block runs only if all conditions are false<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Best Practices<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Always use clear and simple conditions<br>Avoid writing too many nested if statements<br>Use proper indentation for readability<br>Test all possible conditions to avoid errors<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Conclusion<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If, else if, and else statements are essential for decision making in JavaScript. They help developers control how code behaves based on different situations and user inputs.<\/p>\n\n\n<div class=\"yoast-breadcrumbs\"><span><span><a href=\"https:\/\/gigz.pk\/javascript\">Home<\/a><\/span> \u00bb <span class=\"breadcrumb_last\" aria-current=\"page\">JavaScript Fundamentals (Beginner Level) > Operators and Conditions > if, else if, else<\/span><\/span><\/div>\n\n\n<div class=\"schema-faq wp-block-yoast-faq-block\"><div class=\"schema-faq-section\" id=\"faq-question-1777648381823\"><strong class=\"schema-faq-question\"><\/strong> <p class=\"schema-faq-answer\"><\/p> <\/div> <\/div>\n\n\n\n<div class=\"schema-faq wp-block-yoast-faq-block\"><div class=\"schema-faq-section\" id=\"faq-question-1777648381635\"><strong class=\"schema-faq-question\"><\/strong> <p class=\"schema-faq-answer\"><\/p> <\/div> <\/div>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"menu_order":0,"template":"","class_list":["post-83","lesson","type-lesson","status-publish","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.6 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>if, else if, else - Learn JavaScript with GIGZ.PK<\/title>\n<meta name=\"description\" content=\"Learn JavaScript if else and else if statements with simple examples to control program flow and build interactive web apps easily\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/gigz.pk\/javascript\/?lesson=if-else-if-else\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"if, else if, else - Learn JavaScript with GIGZ.PK\" \/>\n<meta property=\"og:description\" content=\"Learn JavaScript if else and else if statements with simple examples to control program flow and build interactive web apps easily\" \/>\n<meta property=\"og:url\" content=\"https:\/\/gigz.pk\/javascript\/?lesson=if-else-if-else\" \/>\n<meta property=\"og:site_name\" content=\"Learn JavaScript with GIGZ.PK\" \/>\n<meta property=\"article:modified_time\" content=\"2026-05-01T15:13:41+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":[\"WebPage\",\"FAQPage\"],\"@id\":\"https:\\\/\\\/gigz.pk\\\/javascript\\\/?lesson=if-else-if-else\",\"url\":\"https:\\\/\\\/gigz.pk\\\/javascript\\\/?lesson=if-else-if-else\",\"name\":\"if, else if, else - Learn JavaScript with GIGZ.PK\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/gigz.pk\\\/javascript\\\/#website\"},\"datePublished\":\"2026-05-01T15:13:40+00:00\",\"dateModified\":\"2026-05-01T15:13:41+00:00\",\"description\":\"Learn JavaScript if else and else if statements with simple examples to control program flow and build interactive web apps easily\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/gigz.pk\\\/javascript\\\/?lesson=if-else-if-else#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/gigz.pk\\\/javascript\\\/?lesson=if-else-if-else\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/gigz.pk\\\/javascript\\\/?lesson=if-else-if-else#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/gigz.pk\\\/javascript\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"JavaScript Fundamentals (Beginner Level) > Operators and Conditions > if, else if, else\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/gigz.pk\\\/javascript\\\/#website\",\"url\":\"https:\\\/\\\/gigz.pk\\\/javascript\\\/\",\"name\":\"Learn JavaScript with GIGZ.PK\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/gigz.pk\\\/javascript\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"if, else if, else - Learn JavaScript with GIGZ.PK","description":"Learn JavaScript if else and else if statements with simple examples to control program flow and build interactive web apps easily","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/gigz.pk\/javascript\/?lesson=if-else-if-else","og_locale":"en_US","og_type":"article","og_title":"if, else if, else - Learn JavaScript with GIGZ.PK","og_description":"Learn JavaScript if else and else if statements with simple examples to control program flow and build interactive web apps easily","og_url":"https:\/\/gigz.pk\/javascript\/?lesson=if-else-if-else","og_site_name":"Learn JavaScript with GIGZ.PK","article_modified_time":"2026-05-01T15:13:41+00:00","twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":["WebPage","FAQPage"],"@id":"https:\/\/gigz.pk\/javascript\/?lesson=if-else-if-else","url":"https:\/\/gigz.pk\/javascript\/?lesson=if-else-if-else","name":"if, else if, else - Learn JavaScript with GIGZ.PK","isPartOf":{"@id":"https:\/\/gigz.pk\/javascript\/#website"},"datePublished":"2026-05-01T15:13:40+00:00","dateModified":"2026-05-01T15:13:41+00:00","description":"Learn JavaScript if else and else if statements with simple examples to control program flow and build interactive web apps easily","breadcrumb":{"@id":"https:\/\/gigz.pk\/javascript\/?lesson=if-else-if-else#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/gigz.pk\/javascript\/?lesson=if-else-if-else"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/gigz.pk\/javascript\/?lesson=if-else-if-else#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/gigz.pk\/javascript"},{"@type":"ListItem","position":2,"name":"JavaScript Fundamentals (Beginner Level) > Operators and Conditions > if, else if, else"}]},{"@type":"WebSite","@id":"https:\/\/gigz.pk\/javascript\/#website","url":"https:\/\/gigz.pk\/javascript\/","name":"Learn JavaScript with GIGZ.PK","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/gigz.pk\/javascript\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/gigz.pk\/javascript\/index.php?rest_route=\/wp\/v2\/lesson\/83","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gigz.pk\/javascript\/index.php?rest_route=\/wp\/v2\/lesson"}],"about":[{"href":"https:\/\/gigz.pk\/javascript\/index.php?rest_route=\/wp\/v2\/types\/lesson"}],"wp:attachment":[{"href":"https:\/\/gigz.pk\/javascript\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=83"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}