

{"id":63136,"date":"2019-08-03T15:39:41","date_gmt":"2019-08-03T10:09:41","guid":{"rendered":"https:\/\/data-flair.training\/blogs\/?p=63136"},"modified":"2021-02-17T21:32:25","modified_gmt":"2021-02-17T16:02:25","slug":"javascript-conditional-statements","status":"publish","type":"post","link":"https:\/\/data-flair.training\/blogs\/javascript-conditional-statements\/","title":{"rendered":"JavaScript Conditional Statements &#8211; Become an expert in its implementation!"},"content":{"rendered":"<div class='__iawmlf-post-loop-links' style='display:none;' data-iawmlf-post-links='[{&quot;id&quot;:1460,&quot;href&quot;:&quot;https:\\\/\\\/developer.mozilla.org\\\/bm\\\/docs\\\/Web\\\/JavaScript&quot;,&quot;archived_href&quot;:&quot;http:\\\/\\\/web-wp.archive.org\\\/web\\\/20201130000822\\\/https:\\\/\\\/developer.mozilla.org\\\/bm\\\/docs\\\/Web\\\/JavaScript&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2025-12-09 07:35:26&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2025-12-14 12:48:38&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2025-12-19 16:01:18&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-01-02 05:32:30&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-01-05 19:50:19&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-01-09 07:53:29&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-01-12 17:53:07&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-01-15 18:05:42&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-01-19 04:19:31&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-01-22 15:51:58&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-01-26 16:36:18&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-01-30 05:54:36&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-02-02 17:35:29&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-02-06 14:42:18&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-02-11 11:19:51&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-02-14 12:03:01&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-02-18 16:15:46&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-02-22 14:15:19&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-02-27 08:10:27&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-03-03 09:04:41&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-03-08 14:29:22&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-03-12 11:33:39&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-03-17 04:22:02&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-03-20 15:25:16&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-03-24 12:07:52&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-03-29 08:48:19&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-04-08 16:30:39&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-04-22 02:42:26&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-04-27 10:57:04&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-05-01 17:54:16&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-05-05 08:23:41&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-05-11 09:47:19&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-05-14 19:09:02&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-05-18 05:55:16&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-05-23 01:38:30&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-05-26 05:15:49&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-05-29 09:07:38&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-06-04 05:11:44&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-06-07 15:48:27&quot;,&quot;http_code&quot;:404}],&quot;broken&quot;:true,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-06-07 15:48:27&quot;,&quot;http_code&quot;:404},&quot;process&quot;:&quot;done&quot;}]'><\/div>\n<p>Moving ahead in our JavaScript tutorial series, today, we will discuss the topic of Conditional Statements in JavaScript. There are various methods to produce the same output and in this article we will go through all of them and try to determine the best approach for a particular situation. This tutorial will cover<em> <strong>if, if..else, else if and switch<\/strong><\/em> statements. Further, we will create a program for the ternary operator that we saw in DataFlair\u2019s tutorial on <em><strong><a href=\"https:\/\/data-flair.training\/blogs\/javascript-operator\/\">JavaScript Operators<\/a>.<\/strong><\/em>\u00a0Later on, we will create a program that will help you calculate your grade.<\/p>\n<p>Before we move on with the different types of conditional statements, let\u2019s first understand what they actually are with the help of a real-life example.<\/p>\n<p><em>We all have been in a situation where you only get your favorite\u00a0toy when you finish your homework. If you don\u2019t, you face punishment. The result you get is based on the condition of whether or not you finished your work. These are similar to how conditional statements work. You continue with your program after checking what the condition says. This is very helpful when you want to execute different statements for different situations<\/em>.<\/p>\n<p>Now let&#8217;s start with the tutorial on JavaScript conditional statements.<\/p>\n<h2>JavaScript Conditional Statements<\/h2>\n<p>Now that you know what conditional statements are, we are going to learn about the different conditional statements that JavaScript provides. We really want you to run these codes as you learn them. This will tell you where you are having trouble in understanding code. And remember, in programming, you need to run all the codes yourself to gain command on them. Practice as much as you can so you can become confident in these codes.<\/p>\n<p>Let&#8217;s take a look at different conditional statements in JavaScript given below:<\/p>\n<h3>1. if Statement<\/h3>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/if-statement.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-66651\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/if-statement.png\" alt=\"if statement - JavaScript Conditional Statements\" width=\"253\" height=\"402\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/if-statement.png 253w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/if-statement-94x150.png 94w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/if-statement-189x300.png 189w\" sizes=\"auto, (max-width: 253px) 100vw, 253px\" \/><\/a><\/p>\n<p>We use an<strong> if <\/strong>statement when you want to check only a specific condition. <strong>\u2018if\u2019<\/strong> is a JavaScript keyword that tells the JavaScript interpreter that you are about to use a conditional statement. The statements inside an if statement will only execute if the condition is <strong>true<\/strong>.<\/p>\n<p>The syntax for an<strong> if<\/strong> statement is as follows:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">if (condition)\r\n{\r\n  \/\/statements to be executed if true\r\n}<\/pre>\n<p>You can add multiple <strong>if<\/strong> statements in your program, as shown in the code. JavaScript interpreter will check every <strong>if<\/strong> statement for its condition.<\/p>\n<p><strong>Code:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&lt;html&gt;\r\n  &lt;body&gt;\r\n\r\n    &lt;script&gt;\r\n      var password = prompt(\"Enter your password.\"); \/\/shows a prompt on your browser with the following text and asks for reply\r\n      if (password == 'DataFlair'){ \/\/checks if password is correct\r\n        document.write(\"Welcome to DataFlair\"); \/\/if password is correct\r\n      }\r\n      if (password != 'DataFlair'){ \/\/checks if password is incorrect\r\n        document.write(\"Access Denied\"); \/\/if password is incorrect\r\n      }\r\n    &lt;\/script&gt;\r\n\r\n  &lt;\/body&gt;\r\n&lt;\/html&gt;\r\n\r\n<\/pre>\n<p><strong>Screenshot:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/ifstatement.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-65947\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/ifstatement.jpg\" alt=\"ifstatement\" width=\"1299\" height=\"741\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/ifstatement.jpg 1299w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/ifstatement-150x86.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/ifstatement-300x171.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/ifstatement-768x438.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/ifstatement-1024x584.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/ifstatement-520x297.jpg 520w\" sizes=\"auto, (max-width: 1299px) 100vw, 1299px\" \/><\/a><\/p>\n<p><strong>Prompt (If the password is correct):<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/if-prompt1.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"img-gray-border aligncenter wp-image-65948 size-full\" style=\"border: 1px solid #eee\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/if-prompt1.jpg\" alt=\"if prompt1\" width=\"1299\" height=\"741\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/if-prompt1.jpg 1299w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/if-prompt1-150x86.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/if-prompt1-300x171.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/if-prompt1-768x438.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/if-prompt1-1024x584.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/if-prompt1-520x297.jpg 520w\" sizes=\"auto, (max-width: 1299px) 100vw, 1299px\" \/><\/a><\/p>\n<p><strong>Output:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/if-op1.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"img-gray-border aligncenter wp-image-65950 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/if-op1.jpg\" alt=\"if op1\" width=\"1299\" height=\"741\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/if-op1.jpg 1299w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/if-op1-150x86.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/if-op1-300x171.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/if-op1-768x438.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/if-op1-1024x584.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/if-op1-520x297.jpg 520w\" sizes=\"auto, (max-width: 1299px) 100vw, 1299px\" \/><\/a><\/p>\n<p><strong>Prompt (If the password is incorrect):<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/if-prompt2.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"img-gray-border aligncenter wp-image-65949 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/if-prompt2.jpg\" alt=\"if prompt2\" width=\"1299\" height=\"741\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/if-prompt2.jpg 1299w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/if-prompt2-150x86.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/if-prompt2-300x171.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/if-prompt2-768x438.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/if-prompt2-1024x584.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/if-prompt2-520x297.jpg 520w\" sizes=\"auto, (max-width: 1299px) 100vw, 1299px\" \/><\/a><\/p>\n<p><strong>Output:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/if-op2.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"img-gray-border aligncenter wp-image-65951 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/if-op2.jpg\" alt=\"if op2\" width=\"1299\" height=\"741\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/if-op2.jpg 1299w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/if-op2-150x86.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/if-op2-300x171.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/if-op2-768x438.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/if-op2-1024x584.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/if-op2-520x297.jpg 520w\" sizes=\"auto, (max-width: 1299px) 100vw, 1299px\" \/><\/a><\/p>\n<p>After the prompt appears in the browser, if we enter the correct password \u201cDataFlair\u201d, we can log in. If we don\u2019t, the browser will deny my access, just like in the second output.<\/p>\n<h3>2. Ternary Operator<\/h3>\n<p>As we discussed in our previous tutorial on JavaScript operators, the ternary operator is a special <a href=\"https:\/\/developer.mozilla.org\/bm\/docs\/Web\/JavaScript\">JavaScript<\/a> operator. It operates on three operands to produce the result. This operator works as an alternative for a single<strong>\u00a0if<\/strong>\u00a0statement. But you should only use it for simple problems. The <strong>if <\/strong>statement avoids confusion and reduces the possibility of error in a complex program.<\/p>\n<p>The syntax for a ternary operator is as follows:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">condition? true: false;\r\nVariable = condition? true: false;<\/pre>\n<p>We don\u2019t always need to store the result in a variable. But if we want to use it later in our code, it is important that we store the value in a variable. If the condition we check is true, variable will store the true operand. If not, it will store the false operand of the code.<\/p>\n<p><strong>Code:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&lt;html&gt;\r\n      &lt;body&gt;\r\n\r\n            &lt;script&gt;\r\n                    var password = prompt(\"Enter your password.\"); \/\/shows a prompt on your browser with the following text and asks for reply\r\n                    var msg = (password == 'DataFlair') ? 'Welcome to DataFlair' : 'Access Denied'; \/\/checks for the condition\r\n                    document.write(msg); \/\/prints the output\r\n            &lt;\/script&gt;\r\n\r\n      &lt;\/body&gt;\r\n&lt;\/html&gt;\r\n\r\n<\/pre>\n<p><strong>Screenshot:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/ternary-statement.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-65952\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/ternary-statement.jpg\" alt=\"ternary statement\" width=\"1299\" height=\"741\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/ternary-statement.jpg 1299w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/ternary-statement-150x86.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/ternary-statement-300x171.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/ternary-statement-768x438.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/ternary-statement-1024x584.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/ternary-statement-520x297.jpg 520w\" sizes=\"auto, (max-width: 1299px) 100vw, 1299px\" \/><\/a><\/p>\n<p><strong>Prompt (If the password is correct):<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/ternary-statement-prompt.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"img-gray-border aligncenter wp-image-65953 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/ternary-statement-prompt.jpg\" alt=\"ternary statement prompt\" width=\"1299\" height=\"741\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/ternary-statement-prompt.jpg 1299w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/ternary-statement-prompt-150x86.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/ternary-statement-prompt-300x171.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/ternary-statement-prompt-768x438.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/ternary-statement-prompt-1024x584.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/ternary-statement-prompt-520x297.jpg 520w\" sizes=\"auto, (max-width: 1299px) 100vw, 1299px\" \/><\/a><\/p>\n<p><strong>Output:<\/strong><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/ternary-statement-op.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"img-gray-border aligncenter wp-image-65954 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/ternary-statement-op.jpg\" alt=\"ternary statement op\" width=\"1299\" height=\"741\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/ternary-statement-op.jpg 1299w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/ternary-statement-op-150x86.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/ternary-statement-op-300x171.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/ternary-statement-op-768x438.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/ternary-statement-op-1024x584.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/ternary-statement-op-520x297.jpg 520w\" sizes=\"auto, (max-width: 1299px) 100vw, 1299px\" \/><\/a><\/p>\n<p><em><strong>For a better understanding, you must explore our blog on <a href=\"https:\/\/data-flair.training\/blogs\/javascript-variable-tutorial\/\">JavaScript Variables<\/a><\/strong><\/em><\/p>\n<h3>3. if&#8230;else Statement<\/h3>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/if-else-statement.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-66658\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/if-else-statement.png\" alt=\"ifelsestatement - JavaScript Conditional Statements\" width=\"459\" height=\"397\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/if-else-statement.png 459w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/if-else-statement-150x130.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/if-else-statement-300x259.png 300w\" sizes=\"auto, (max-width: 459px) 100vw, 459px\" \/><\/a><\/p>\n<p>This is another method to produce the same output as with<strong> if<\/strong> statements and the<strong> ternary<\/strong> <strong>operator<\/strong>. We use<strong> if&#8230;else<\/strong> statements for this purpose. The interpreter checks if the condition is true. If yes, then the statements inside the if block is executed and if not, the else block is executed. Unlike in if statements as in the example above, we don\u2019t need to specify any condition inside an else statement.<\/p>\n<p><strong>else<\/strong> is always used with <strong>if<\/strong> statements. The syntax for an <strong>if&#8230;else statement<\/strong> is as follows:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">if (condition)\r\n{\r\n  \/\/code if condition is true\r\n}else{\r\n  \/\/code if condition is false\r\n}<\/pre>\n<p><strong>Code:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&lt;html&gt;\r\n  &lt;body&gt;\r\n\r\n    &lt;script&gt;\r\n      var password = prompt(\"Enter your password.\"); \/\/shows a prompt on your browser with the following text and asks for reply\r\n      if (password == 'DataFlair'){ \/\/checks if password is correct\r\n        document.write(\"Welcome to DataFlair\"); \/\/if password is correct\r\n      }\r\n      else{\r\n        document.write(\"Access Denied\"); \/\/if password is incorrect\r\n      }\r\n    &lt;\/script&gt;\r\n\r\n  &lt;\/body&gt;\r\n&lt;\/html&gt;<\/pre>\n<p><b>Screenshot:<\/b><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/if.else_.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-65955\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/if.else_.jpg\" alt=\"if.else\" width=\"1299\" height=\"741\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/if.else_.jpg 1299w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/if.else_-150x86.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/if.else_-300x171.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/if.else_-768x438.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/if.else_-1024x584.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/if.else_-520x297.jpg 520w\" sizes=\"auto, (max-width: 1299px) 100vw, 1299px\" \/><\/a><\/p>\n<p><strong>Output (If the password is correct):<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/if-prompt2-1.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"img-gray-border aligncenter wp-image-65956 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/if-prompt2-1.jpg\" alt=\"if prompt2\" width=\"1299\" height=\"741\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/if-prompt2-1.jpg 1299w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/if-prompt2-1-150x86.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/if-prompt2-1-300x171.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/if-prompt2-1-768x438.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/if-prompt2-1-1024x584.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/if-prompt2-1-520x297.jpg 520w\" sizes=\"auto, (max-width: 1299px) 100vw, 1299px\" \/><\/a><\/p>\n<p><strong>Output:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/if.else-op1.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"img-gray-border aligncenter wp-image-65957 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/if.else-op1.jpg\" alt=\"if.else op1\" width=\"1299\" height=\"741\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/if.else-op1.jpg 1299w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/if.else-op1-150x86.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/if.else-op1-300x171.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/if.else-op1-768x438.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/if.else-op1-1024x584.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/if.else-op1-520x297.jpg 520w\" sizes=\"auto, (max-width: 1299px) 100vw, 1299px\" \/><\/a><\/p>\n<p>Excellent! Now you know how to use these basic conditional statements in your program. We have a task to complete now. Remember we talked about creating your grade sheet based on your marks? You\u2019re wondering how to do that, right? We will do it with the help of either <strong>nested if&#8230;else<\/strong> statements or <strong>if&#8230;else if&#8230;else statements.<\/strong><\/p>\n<p>Suppose you scored 400 out of 500 in the examination. We have to calculate the grade as per the following table:<\/p>\n<table dir=\"ltr\">\n<colgroup>\n<col width=\"100\" \/>\n<col width=\"100\" \/>\n<col width=\"100\" \/><\/colgroup>\n<tbody>\n<tr>\n<td style=\"text-align: center\"><strong>Percentage<\/strong><\/td>\n<td style=\"text-align: center\"><strong>Grade<\/strong><\/td>\n<td style=\"text-align: center\"><strong>Remark<\/strong><\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center\">&gt; 90<\/td>\n<td style=\"text-align: center\">\u00a0 A+<\/td>\n<td style=\"text-align: center\">Outstanding<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center\">&lt; 90 and &gt; 80<\/td>\n<td style=\"text-align: center\">A<\/td>\n<td style=\"text-align: center\">Excellent<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center\">&lt; 80 and &gt; 70<\/td>\n<td style=\"text-align: center\">B<\/td>\n<td style=\"text-align: center\">Very good<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center\">&lt; 70 and &gt; 60<\/td>\n<td style=\"text-align: center\">C<\/td>\n<td style=\"text-align: center\">Good<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center\">&lt; 60 and &gt; 50<\/td>\n<td style=\"text-align: center\">D<\/td>\n<td style=\"text-align: center\">Can do better<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center\">&lt; 50<\/td>\n<td style=\"text-align: center\">E<\/td>\n<td style=\"text-align: center\">Try harder<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>These statements are going to modify our flowchart a bit. Now we have to check multiple conditions at once to proceed.<\/p>\n<p><em><strong>Did you check our blog on <a href=\"https:\/\/data-flair.training\/blogs\/javascript-uses\/\">Latest JavaScript Applications<\/a>?<\/strong><\/em><\/p>\n<h3>4. Nested if&#8230;else Statements<\/h3>\n<p style=\"text-align: left\"><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/nested-if-else.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-66652\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/nested-if-else.png\" alt=\"nested if else - JavaScript Conditional Statements\" width=\"502\" height=\"455\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/nested-if-else.png 502w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/nested-if-else-150x136.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/nested-if-else-300x272.png 300w\" sizes=\"auto, (max-width: 502px) 100vw, 502px\" \/><\/a><\/p>\n<p>This is a method to check multiple statements. But this is not always an ideal one. You should be very careful in using these statements. <strong>Nested if&#8230;else<\/strong> statements mean that there are <strong>if&#8230;else<\/strong> statements inside an if or an else statement.<\/p>\n<p>The syntax for these statements will be something like this:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">if (condition1)\r\n{\r\n  ...\r\n  if (condition2)\r\n  {\r\n    \/\/ code if both conditions are true\r\n  }else{\r\n    \/\/code if condition1 is true but condition2 is false\r\n  }\r\n}else{\r\n  \/\/code if condition1 is false\r\n}\r\n<\/pre>\n<p>Or<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">if (condition1)\r\n{\r\n  \/\/code if condition1 is true\r\n\r\n}else{\r\n  ...\r\n  if (condition2)\r\n  {\r\n    \/\/ code if condition1 is false but condition2 is true\r\n  }else{\r\n    \/\/code if both conditions are false\r\n  }\r\n}<\/pre>\n<p>Let\u2019s calculate our grade with these statements.<\/p>\n<p><strong>Code:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&lt;html&gt;\r\n  &lt;body&gt;\r\n\r\n    &lt;script&gt;\r\n      var marks = prompt(\"DataFlair: Enter your marks (out of 500)\"); \/\/asks for your marks\r\n      var percentage = marks \/ 500 * 100; \/\/calculates percentage\r\n      if (percentage &gt; 90) {\r\n        document.write(\"Your percentage is: A+\"); \/\/case1\r\n      }else{\r\n        if (percentage &gt; 80) {\r\n          document.write(\"Your grade is: A\"); \/\/case2\r\n        }else{\r\n          if (percentage &gt; 70) {\r\n            document.write(\"Your grade is: B\"); \/\/case3\r\n          }else{\r\n            if (percentage &gt; 60) {\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t \r\n                                                     document.write(\"Your grade is: C\"); \/\/case4\r\n            }else{\r\n              if (percentage &gt; 50) {\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t \r\n                                                     document.write(\"Your grade is: D\"); \/\/case5\r\n              }else{\r\n                                                     document.write(\"Your grade is: E\"); \/\/case6\r\n              }\r\n            }\r\n          }\r\n        }\r\n      }\r\n    &lt;\/script&gt;\r\n\r\n  &lt;\/body&gt;\r\n&lt;\/html&gt;<\/pre>\n<p><b>Screenshot:<\/b><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/nested-if.else_.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-65958\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/nested-if.else_.jpg\" alt=\"nested if.else\" width=\"1299\" height=\"741\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/nested-if.else_.jpg 1299w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/nested-if.else_-150x86.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/nested-if.else_-300x171.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/nested-if.else_-768x438.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/nested-if.else_-1024x584.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/nested-if.else_-520x297.jpg 520w\" sizes=\"auto, (max-width: 1299px) 100vw, 1299px\" \/><\/a><\/p>\n<p><strong>Prompt:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/nested-if.else-prompt.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"img-gray-border aligncenter wp-image-65959 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/nested-if.else-prompt.jpg\" alt=\"nested if.else prompt - JavaScript Conditional Statements\" width=\"1299\" height=\"741\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/nested-if.else-prompt.jpg 1299w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/nested-if.else-prompt-150x86.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/nested-if.else-prompt-300x171.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/nested-if.else-prompt-768x438.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/nested-if.else-prompt-1024x584.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/nested-if.else-prompt-520x297.jpg 520w\" sizes=\"auto, (max-width: 1299px) 100vw, 1299px\" \/><\/a><\/p>\n<p><strong>Output:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/nested-if.else-op.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"img-gray-border aligncenter wp-image-65960 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/nested-if.else-op.jpg\" alt=\"nested if.else op - JavaScript Conditional Statements\" width=\"1299\" height=\"741\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/nested-if.else-op.jpg 1299w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/nested-if.else-op-150x86.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/nested-if.else-op-300x171.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/nested-if.else-op-768x438.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/nested-if.else-op-1024x584.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/nested-if.else-op-520x297.jpg 520w\" sizes=\"auto, (max-width: 1299px) 100vw, 1299px\" \/><\/a><\/p>\n<h3>5. if&#8230;else if\u2026 else Statements<\/h3>\n<p style=\"text-align: left\"><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/if-else-if-else-statement.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-66653\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/if-else-if-else-statement.png\" alt=\"if else if else statement\" width=\"593\" height=\"519\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/if-else-if-else-statement.png 593w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/if-else-if-else-statement-150x131.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/if-else-if-else-statement-300x263.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/if-else-if-else-statement-520x455.png 520w\" sizes=\"auto, (max-width: 593px) 100vw, 593px\" \/><\/a><\/p>\n<p>We got the desired output from the previous technique but it wasn\u2019t very efficient, don\u2019t you think so? You have to check so many conditions and it might be possible that an error occurs. Your complete code will be useless with a single mistake. You want a better option for this task. One solution is to use<strong> if&#8230;else if&#8230;else statements.<\/strong> The interpreter will check the<strong> if<\/strong> condition first. If it is true, the if block runs; if false, it will move onto the <strong>else if<\/strong> condition. This checks if the condition is <strong>true<\/strong> for the second condition but <strong>false<\/strong> for the first one. This process continues for all the <strong>else if<\/strong> statements. If none of the conditions is <strong>true<\/strong>, the code in the <strong>else<\/strong> block is run.<\/p>\n<p>The syntax for this technique is as follows:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">if (condition1)\r\n{\r\n  \/\/code if condition1 is true\r\n}else if (condition2)\r\n{\r\n  \/\/code if condition2 is true\r\n}\r\n...\r\nelse if (conditionN)\r\n{\r\n  \/\/code if conditionN is true\r\n}else{\r\n  \/\/code if all above conditions are false\r\n}<\/pre>\n<p><strong>Code:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&lt;html&gt;\r\n  &lt;body&gt;\r\n\r\n    &lt;script&gt;\r\n      var marks = prompt(\"DataFlair: Enter your marks (out of 500)\"); \/\/asks for your marks\r\n      var percentage = marks \/ 500 * 100; \/\/calculates percentage\r\n      if (percentage &gt; 90) {\r\n        document.write(\"Your percentage is: A+\"); \/\/case1\r\n      }else if (percentage &gt; 80) {\r\n        document.write(\"Your percentage is: A\"); \/\/case2\r\n      }else if (percentage &gt; 70) {\r\n        document.write(\"Your percentage is: B\"); \/\/case3\r\n      }else if (percentage &gt; 60) {\r\n        document.write(\"Your percentage is: C\"); \/\/case4\r\n      }else if (percentage &gt; 50) {\r\n        document.write(\"Your percentage is: D\"); \/\/case5\r\n      }else{\r\n        document.write(\"Your percentage is: E\"); \/\/case6\r\n      }\r\n    &lt;\/script&gt;\r\n\r\n  &lt;\/body&gt;\r\n&lt;\/html&gt;<\/pre>\n<p><strong>Screenshot:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/if-else-if-else.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-66169 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/if-else-if-else.jpg\" alt=\"if-else-if-else - JavaScript Conditional Statements\" width=\"1299\" height=\"741\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/if-else-if-else.jpg 1299w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/if-else-if-else-150x86.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/if-else-if-else-300x171.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/if-else-if-else-768x438.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/if-else-if-else-1024x584.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/if-else-if-else-520x297.jpg 520w\" sizes=\"auto, (max-width: 1299px) 100vw, 1299px\" \/><\/a><\/p>\n<p><b>Output:<a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/if-else-if-else-output.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"img-gray-border aligncenter wp-image-66170 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/if-else-if-else-output.jpg\" alt=\"if-else-if-else-output - JavaScript Conditional Statements\" width=\"1299\" height=\"741\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/if-else-if-else-output.jpg 1299w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/if-else-if-else-output-150x86.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/if-else-if-else-output-300x171.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/if-else-if-else-output-768x438.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/if-else-if-else-output-1024x584.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/if-else-if-else-output-520x297.jpg 520w\" sizes=\"auto, (max-width: 1299px) 100vw, 1299px\" \/><\/a><\/b><\/p>\n<p>This is better. We have the same output as before, but now the code is easier to read and understand.<\/p>\n<h3>6. switch Statements<\/h3>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/conditional-statement-switch.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-66710\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/conditional-statement-switch.png\" alt=\"conditional statement switch\" width=\"443\" height=\"702\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/conditional-statement-switch.png 443w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/conditional-statement-switch-95x150.png 95w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/conditional-statement-switch-189x300.png 189w\" sizes=\"auto, (max-width: 443px) 100vw, 443px\" \/><\/a><\/p>\n<p>We also have a special set of conditional statements that are very helpful when we want to execute code based on a specific condition. These are the switch statements. We use the keywords<strong> switch, case, and break<\/strong> for these statements. The condition of whichever case is <strong>true<\/strong>, that block executes.<\/p>\n<p>The syntax for these statements is like this:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">switch (expression)\r\n{\r\n  case 1: \/\/code executed if the expression evaluates to 1\r\n        break;\r\n        case 2: \/\/code executed if the expression evaluates to 2\r\n        break;\r\n        ...\r\n        case N: \/\/code executed if the expression evaluates to N\r\n        break;\r\n        default: \/\/code executed if none of the cases works\r\n}<\/pre>\n<p>The <strong>switch<\/strong> keyword tells the interpreter that the following code is for switch statements. It executes on the basis of the value calculated by the expression. If none of the cases satisfies the expression, <strong>default<\/strong> case executes. We recommend you to use this case in every switch case. <strong>break<\/strong> is an important keyword in these statements. These help the interpreter to break out of the switch block. If you don\u2019t add this keyword after every case, the interpreter will check all other switch cases, even after one of the cases has been satisfied.<\/p>\n<p><strong>Code:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&lt;html&gt;\r\n  &lt;body&gt;\r\n\r\n    &lt;script&gt;\r\n      var alphabet = prompt(\"DataFlair says Enter an alphabet\"); \/\/asks for an alphabet\r\n      switch (alphabet)\r\n      {\r\n        case 'a': document.write(\"Vowel a\");\r\n          break; \/\/breaks out of switch block if case 'a' is true\r\n        case 'A': document.write(\"Vowel A\");\r\n          break;\r\n        case 'e': document.write(\"Vowel e\");\r\n          break;\r\n        case 'E': document.write(\"Vowel E\");\r\n          break;\r\n        case 'i': document.write(\"Vowel i\");\r\n          break;\r\n        case 'I': document.write(\"Vowel I\");\r\n          break;\r\n        case 'o': document.write(\"Vowel o\");\r\n          break;\r\n        case 'O': document.write(\"Vowel O\");\r\n          break;\r\n        case 'u': document.write(\"Vowel u\");\r\n          break;\r\n        case 'U': document.write(\"Vowel U\"); \/\/prints vowel with its name\r\n          break;\r\n        default: document.write(\"Not a vowel\"); \/\/returns not a vowel\r\n      }\r\n    &lt;\/script&gt;\r\n\r\n  &lt;\/body&gt;\r\n&lt;\/html&gt;<\/pre>\n<p><b>Screenshot:<\/b><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/switch.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-65963 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/switch.jpg\" alt=\"switch - JavaScript Conditional Statements\" width=\"1299\" height=\"741\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/switch.jpg 1299w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/switch-150x86.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/switch-300x171.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/switch-768x438.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/switch-1024x584.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/switch-520x297.jpg 520w\" sizes=\"auto, (max-width: 1299px) 100vw, 1299px\" \/><\/a><\/p>\n<p><strong>Output (if I enter u in the prompt):<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/switch-prompt.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"img-gray-border aligncenter wp-image-65964 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/switch-prompt.jpg\" alt=\"switch prompt - JavaScript Conditional Statements\" width=\"1299\" height=\"741\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/switch-prompt.jpg 1299w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/switch-prompt-150x86.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/switch-prompt-300x171.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/switch-prompt-768x438.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/switch-prompt-1024x584.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/switch-prompt-520x297.jpg 520w\" sizes=\"auto, (max-width: 1299px) 100vw, 1299px\" \/><\/a><\/p>\n<p><strong>Output:<\/strong><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/switch-op1.jpg\"><br \/>\n<\/a><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/switch-op1.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"img-gray-border aligncenter wp-image-65965 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/switch-op1.jpg\" alt=\"switch op1 - JavaScript Conditional Statements\" width=\"1299\" height=\"741\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/switch-op1.jpg 1299w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/switch-op1-150x86.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/switch-op1-300x171.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/switch-op1-768x438.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/switch-op1-1024x584.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/switch-op1-520x297.jpg 520w\" sizes=\"auto, (max-width: 1299px) 100vw, 1299px\" \/><\/a><\/p>\n<p><strong>Output (if I enter d in the prompt):<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/switch-op2.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"img-gray-border aligncenter wp-image-65966 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/switch-op2.jpg\" alt=\"switch op2 - JavaScript Conditional Statements\" width=\"1299\" height=\"741\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/switch-op2.jpg 1299w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/switch-op2-150x86.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/switch-op2-300x171.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/switch-op2-768x438.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/switch-op2-1024x584.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/switch-op2-520x297.jpg 520w\" sizes=\"auto, (max-width: 1299px) 100vw, 1299px\" \/><\/a><\/p>\n<h2>Summary<\/h2>\n<p>Here we come to the end of our tutorial on JavaScript conditional statements. In this article, we learned about the various conditional statements.\u00a0The concept of conditional statements is common for all the programming languages, including Java. Only syntax changes when you switch between different programming languages. We hope you practiced these codes with me as practicing is the key to understanding programming.<\/p>\n<p><em><strong>Now, you must go through our next article on <a href=\"https:\/\/data-flair.training\/blogs\/javascript-function\/\">JavaScript Functions<\/a><\/strong><\/em><\/p>\n<p>Any queries or feedback from your side? Share them in the comment section below.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Moving ahead in our JavaScript tutorial series, today, we will discuss the topic of Conditional Statements in JavaScript. There are various methods to produce the same output and in this article we will go&#46;&#46;&#46;<\/p>\n","protected":false},"author":7,"featured_media":65968,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18979],"tags":[20581,20582,20579,20583,20580],"class_list":["post-63136","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-javascript","tag-if-statements","tag-if-else-statements","tag-javascript-conditional-statements","tag-switch-statements","tag-ternary-operators"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>JavaScript Conditional Statements - Become an expert in its implementation! - DataFlair<\/title>\n<meta name=\"description\" content=\"Learn to implement different types of JavaScript conditional statements with the help of syntax &amp; examples. Also, learn to create program for ternary operator.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/data-flair.training\/blogs\/javascript-conditional-statements\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"JavaScript Conditional Statements - Become an expert in its implementation! - DataFlair\" \/>\n<meta property=\"og:description\" content=\"Learn to implement different types of JavaScript conditional statements with the help of syntax &amp; examples. Also, learn to create program for ternary operator.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/data-flair.training\/blogs\/javascript-conditional-statements\/\" \/>\n<meta property=\"og:site_name\" content=\"DataFlair\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/DataFlairWS\/\" \/>\n<meta property=\"article:published_time\" content=\"2019-08-03T10:09:41+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-02-17T16:02:25+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/JavaScript-Conditional-Statement-.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"802\" \/>\n\t<meta property=\"og:image:height\" content=\"420\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"DataFlair Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:site\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"DataFlair Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"10 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"JavaScript Conditional Statements - Become an expert in its implementation! - DataFlair","description":"Learn to implement different types of JavaScript conditional statements with the help of syntax & examples. Also, learn to create program for ternary operator.","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:\/\/data-flair.training\/blogs\/javascript-conditional-statements\/","og_locale":"en_US","og_type":"article","og_title":"JavaScript Conditional Statements - Become an expert in its implementation! - DataFlair","og_description":"Learn to implement different types of JavaScript conditional statements with the help of syntax & examples. Also, learn to create program for ternary operator.","og_url":"https:\/\/data-flair.training\/blogs\/javascript-conditional-statements\/","og_site_name":"DataFlair","article_publisher":"https:\/\/www.facebook.com\/DataFlairWS\/","article_published_time":"2019-08-03T10:09:41+00:00","article_modified_time":"2021-02-17T16:02:25+00:00","og_image":[{"width":802,"height":420,"url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/JavaScript-Conditional-Statement-.jpg","type":"image\/jpeg"}],"author":"DataFlair Team","twitter_card":"summary_large_image","twitter_creator":"@DataFlairWS","twitter_site":"@DataFlairWS","twitter_misc":{"Written by":"DataFlair Team","Est. reading time":"10 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/data-flair.training\/blogs\/javascript-conditional-statements\/#article","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/javascript-conditional-statements\/"},"author":{"name":"DataFlair Team","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/beb0cab24b7aa54423a3b50e669a9dcd"},"headline":"JavaScript Conditional Statements &#8211; Become an expert in its implementation!","datePublished":"2019-08-03T10:09:41+00:00","dateModified":"2021-02-17T16:02:25+00:00","mainEntityOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/javascript-conditional-statements\/"},"wordCount":1337,"commentCount":0,"publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/javascript-conditional-statements\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/JavaScript-Conditional-Statement-.jpg","keywords":["if Statements","if..else Statements","JavaScript Conditional Statements","Switch Statements","Ternary Operators"],"articleSection":["JavaScript Tutorial"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/data-flair.training\/blogs\/javascript-conditional-statements\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/data-flair.training\/blogs\/javascript-conditional-statements\/","url":"https:\/\/data-flair.training\/blogs\/javascript-conditional-statements\/","name":"JavaScript Conditional Statements - Become an expert in its implementation! - DataFlair","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/#website"},"primaryImageOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/javascript-conditional-statements\/#primaryimage"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/javascript-conditional-statements\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/JavaScript-Conditional-Statement-.jpg","datePublished":"2019-08-03T10:09:41+00:00","dateModified":"2021-02-17T16:02:25+00:00","description":"Learn to implement different types of JavaScript conditional statements with the help of syntax & examples. Also, learn to create program for ternary operator.","breadcrumb":{"@id":"https:\/\/data-flair.training\/blogs\/javascript-conditional-statements\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/data-flair.training\/blogs\/javascript-conditional-statements\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/javascript-conditional-statements\/#primaryimage","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/JavaScript-Conditional-Statement-.jpg","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/JavaScript-Conditional-Statement-.jpg","width":802,"height":420,"caption":"JavaScript Conditional Statement"},{"@type":"BreadcrumbList","@id":"https:\/\/data-flair.training\/blogs\/javascript-conditional-statements\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog Home","item":"https:\/\/data-flair.training\/blogs\/"},{"@type":"ListItem","position":2,"name":"JavaScript Tutorial","item":"https:\/\/data-flair.training\/blogs\/category\/javascript\/"},{"@type":"ListItem","position":3,"name":"JavaScript Conditional Statements &#8211; Become an expert in its implementation!"}]},{"@type":"WebSite","@id":"https:\/\/data-flair.training\/blogs\/#website","url":"https:\/\/data-flair.training\/blogs\/","name":"DataFlair","description":"Learn Today. Lead Tomorrow.","publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/data-flair.training\/blogs\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/data-flair.training\/blogs\/#organization","name":"DataFlair","url":"https:\/\/data-flair.training\/blogs\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","width":106,"height":48,"caption":"DataFlair"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/DataFlairWS\/","https:\/\/x.com\/DataFlairWS","https:\/\/www.linkedin.com\/company\/dataflair-web-services-pvt-ltd\/","https:\/\/www.youtube.com\/user\/DataFlairWS"]},{"@type":"Person","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/beb0cab24b7aa54423a3b50e669a9dcd","name":"DataFlair Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/c322416204232f4dd97ef3901b0a499a5d34d7ba7fe333f4bfe53a907873d293?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/c322416204232f4dd97ef3901b0a499a5d34d7ba7fe333f4bfe53a907873d293?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/c322416204232f4dd97ef3901b0a499a5d34d7ba7fe333f4bfe53a907873d293?s=96&d=mm&r=g","caption":"DataFlair Team"},"description":"DataFlair Team specializes in creating clear, actionable content on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Backed by industry expertise, we make learning easy and career-oriented for beginners and pros alike.","url":"https:\/\/data-flair.training\/blogs\/author\/dfteam3\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/63136","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/comments?post=63136"}],"version-history":[{"count":17,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/63136\/revisions"}],"predecessor-version":[{"id":66712,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/63136\/revisions\/66712"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media\/65968"}],"wp:attachment":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media?parent=63136"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/categories?post=63136"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/tags?post=63136"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}