{"id":117593,"date":"2023-05-31T11:51:11","date_gmt":"2023-05-31T08:51:11","guid":{"rendered":"https:\/\/www.javacodegeeks.com\/?p=117593"},"modified":"2023-05-31T11:51:13","modified_gmt":"2023-05-31T08:51:13","slug":"conditionals-in-javascript","status":"publish","type":"post","link":"https:\/\/www.javacodegeeks.com\/2023\/05\/conditionals-in-javascript.html","title":{"rendered":"Conditionals In JavaScript"},"content":{"rendered":"<p>Conditional statements, also known as conditionals, are an essential part of programming languages. They allow you to make decisions and execute different blocks of code based on certain conditions. Conditional statements enable your code to respond dynamically to different scenarios, making your programs more flexible and powerful.<\/p>\n<p>In general, conditional statements evaluate a condition or a set of conditions and execute specific code blocks if the condition(s) is true or false.<\/p>\n<h2 class=\"wp-block-heading\">How can you Implement Conditions<\/h2>\n<p>Conditions can be implemented using the following ways:<\/p>\n<p>Conditions can be implemented in various ways in programming languages. Let&#8217;s explore some common methods along with code examples:<\/p>\n<p><strong>1. Comparison Operators:<\/strong> Comparison operators allow you to compare values and evaluate conditions based on the result. Here are some commonly used comparison operators:<\/p>\n<ul class=\"wp-block-list\">\n<li>Equal to (<code>==<\/code>): Checks if two values are equal.<\/li>\n<li>Not equal to (<code>!=<\/code>): Checks if two values are not equal.<\/li>\n<li>Strict equal to (<code>===<\/code>): Checks if two values are equal in value and type.<\/li>\n<li>Strict not equal to (<code>!==<\/code>): Checks if two values are not equal in value or type.<\/li>\n<li>Greater than (<code>&gt;<\/code>): Checks if one value is greater than another.<\/li>\n<li>Less than (<code>&lt;<\/code>): Checks if one value is less than another.<\/li>\n<li>Greater than or equal to (<code>&gt;=<\/code>): Checks if one value is greater than or equal to another.<\/li>\n<li>Less than or equal to (<code>&lt;=<\/code>): Checks if one value is less than or equal to another.<\/li>\n<\/ul>\n<p>Example:<\/p>\n<pre class=\"brush:js\">\nlet x = 5;\nlet y = 10;\n\nif (x &lt; y) {\n  console.log(\"x is less than y\");\n} else if (x &gt; y) {\n  console.log(\"x is greater than y\");\n} else {\n  console.log(\"x is equal to y\");\n}\n<\/pre>\n<p><strong>2. Logical Operators:<\/strong> Logical operators allow you to combine conditions and create more complex expressions. The commonly used logical operators are:<\/p>\n<ul class=\"wp-block-list\">\n<li>Logical AND (<code>&amp;&amp;<\/code>): Returns true if both conditions are true.<\/li>\n<li>Logical OR (<code>||<\/code>): Returns true if at least one condition is true.<\/li>\n<li>Logical NOT (<code>!<\/code>): Inverts the result of a condition.<\/li>\n<\/ul>\n<p>Example:<\/p>\n<pre class=\"brush:js\">\nlet age = 25;\nlet hasLicense = true;\n\nif (age &gt;= 18 &amp;&amp; hasLicense) {\n  console.log(\"You are eligible to drive\");\n} else {\n  console.log(\"You are not eligible to drive\");\n}\n<\/pre>\n<p><strong>3. Ternary Operator:<\/strong> The ternary operator allows you to write concise conditional expressions. It has the following syntax: <code>condition ? expression1 : expression2<\/code>. If the condition is true, <code>expression1<\/code> is evaluated; otherwise, <code>expression2<\/code> is evaluated.<\/p>\n<p>Example:<\/p>\n<pre class=\"brush:js\">\nlet number = 7;\nlet result = number % 2 === 0 ? \"Even\" : \"Odd\";\nconsole.log(result); \/\/ Output: Odd\n<\/pre>\n<p><strong>4. Switch Statement:<\/strong> The switch statement provides an alternative to multiple <code>if...else if<\/code> statements when comparing a single value against multiple cases. It simplifies the code and improves readability.<\/p>\n<p>Example:<\/p>\n<pre class=\"brush:js\">\nlet day = \"Monday\";\n\nswitch (day) {\n  case \"Monday\":\n    console.log(\"It's Monday\");\n    break;\n  case \"Tuesday\":\n    console.log(\"It's Tuesday\");\n    break;\n  case \"Wednesday\":\n    console.log(\"It's Wednesday\");\n    break;\n  default:\n    console.log(\"It's another day\");\n}\n<\/pre>\n<p>These are some common approaches to implementing conditions in programming. However, the specific method to use depends on the language you are working with and the requirements of your program.<\/p>\n<h2 class=\"wp-block-heading\">Conditional Statements<\/h2>\n<p>In general, conditional statements evaluate a condition or a set of conditions and execute specific code blocks if the condition(s) is true or false. The most common types of conditional statements are:<\/p>\n<ul class=\"wp-block-list\">\n<li><strong>if statement:<\/strong> The <code>if<\/code> statement is the simplest form of a conditional statement. It checks a condition and executes a block of code if the condition is true. Here&#8217;s the basic syntax:<\/li>\n<\/ul>\n<pre class=\"brush:js\">\nif (condition) {\n  \/\/ code to be executed if the condition is true\n}\n<\/pre>\n<p>Here&#8217;s an example of using the <code>if<\/code> statement:<\/p>\n<pre class=\"brush:js\">\nlet age = 20;\n\nif (age &gt;= 18) {\n  console.log(\"You are eligible to vote.\"); \/\/ This code block will be executed if the condition is true.\n}\n\nconsole.log(\"End of program.\");\n<\/pre>\n<p>In this example, we have a variable <code>age<\/code> that represents a person&#8217;s age. The <code>if<\/code> statement checks if the <code>age<\/code> is greater than or equal to 18. If the condition evaluates to true, the code block inside the <code>if<\/code> statement will be executed, and the message &#8220;You are eligible to vote.&#8221; will be printed to the console. If the condition is false, the code block will be skipped, and the program will move on to the next line after the <code>if<\/code> statement.<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<p>Regardless of the condition&#8217;s outcome, the code outside the <code>if<\/code> statement will always be executed. In this case, &#8220;End of program.&#8221; will be printed to the console.<\/p>\n<p>Note that the code inside the <code>if<\/code> statement is enclosed within curly braces <code>{}<\/code>. If the code block inside the <code>if<\/code> statement contains only one statement, the curly braces can be omitted. However, it is considered a good practice to always use curly braces to avoid any confusion or mistakes in the code.<\/p>\n<p>The <code>if<\/code> statement is the most basic form of conditional statement and allows you to execute a block of code based on a single condition.<\/p>\n<ul class=\"wp-block-list\">\n<li><strong>if&#8230;else statement:<\/strong> The <code>if...else<\/code> statement provides an alternative execution path. It checks a condition and executes one block of code if the condition is true, and a different block of code if the condition is false. Here&#8217;s the syntax:<\/li>\n<\/ul>\n<pre class=\"brush:js\">\nif (condition) {\n  \/\/ code to be executed if the condition is true\n} else {\n  \/\/ code to be executed if the condition is false\n}\n<\/pre>\n<p>Here&#8217;s an example of using the <code>if...else<\/code> statement:<\/p>\n<pre class=\"brush:js\">\nlet time = 14;\n\nif (time &lt; 12) {\n  console.log(\"Good morning!\");\n} else {\n  console.log(\"Good afternoon!\");\n}\n\nconsole.log(\"End of program.\");\n<\/pre>\n<p>In this example, we have a variable <code>time<\/code> that represents the hour of the day. The <code>if...else<\/code> statement checks if the <code>time<\/code> is less than 12. If the condition evaluates to true, the code block inside the <code>if<\/code> statement will be executed, and the message &#8220;Good morning!&#8221; will be printed to the console. If the condition is false, the code block inside the <code>else<\/code> statement will be executed, and the message &#8220;Good afternoon!&#8221; will be printed to the console.<\/p>\n<p>In this case, since the value of <code>time<\/code> is 14 (2 PM), the condition <code>time &lt; 12<\/code> is false. Hence, the code block inside the <code>else<\/code> statement will be executed, and &#8220;Good afternoon!&#8221; will be printed to the console.<\/p>\n<p>After executing the appropriate code block, the program continues to the next line after the <code>if...else<\/code> statement, and &#8220;End of program.&#8221; will be printed to the console.<\/p>\n<p>The <code>if...else<\/code> statement allows you to execute different code blocks based on a condition. If the condition is true, the code block inside the <code>if<\/code> statement is executed. If the condition is false, the code block inside the <code>else<\/code> statement is executed.<\/p>\n<ul class=\"wp-block-list\">\n<li><strong>if&#8230;else if&#8230;else statement:<\/strong> The <code>if...else if...else<\/code> statement allows you to evaluate multiple conditions and execute the corresponding block of code based on the first true condition. Here&#8217;s the syntax:<\/li>\n<\/ul>\n<pre class=\"brush:js\">\nif (condition1) {\n  \/\/ code to be executed if condition1 is true\n} else if (condition2) {\n  \/\/ code to be executed if condition2 is true\n} else {\n  \/\/ code to be executed if all conditions are false\n}\n<\/pre>\n<p>Here&#8217;s an example of using the <code>if...else if...else<\/code> statement:<\/p>\n<pre class=\"brush:js\">\nlet num = 0;\n\nif (num &gt; 0) {\n  console.log(\"The number is positive.\");\n} else if (num &lt; 0) {\n  console.log(\"The number is negative.\");\n} else {\n  console.log(\"The number is zero.\");\n}\n\nconsole.log(\"End of program.\");\n<\/pre>\n<p>In this example, we have a variable <code>num<\/code> that represents a number. The <code>if...else if...else<\/code> statement evaluates multiple conditions in sequence and executes the code block associated with the first condition that evaluates to true.<\/p>\n<ul class=\"wp-block-list\">\n<li>If <code>num<\/code> is greater than 0, the first condition <code>num &gt; 0<\/code> is true, and the code block inside the corresponding <code>if<\/code> statement will be executed, printing &#8220;The number is positive.&#8221; to the console.<\/li>\n<li>If the first condition is false, the program moves to the next condition, <code>num &lt; 0<\/code>. If <code>num<\/code> is less than 0, the second condition is true, and the code block inside the corresponding <code>else if<\/code> statement will be executed, printing &#8220;The number is negative.&#8221; to the console.<\/li>\n<li>If both the first and second conditions are false, the program executes the code block inside the <code>else<\/code> statement, printing &#8220;The number is zero.&#8221; to the console.<\/li>\n<\/ul>\n<p>After executing the appropriate code block, the program continues to the next line after the <code>if...else if...else<\/code> statement, and &#8220;End of program.&#8221; will be printed to the console.<\/p>\n<p>The <code>if...else if...else<\/code> statement allows you to evaluate multiple conditions and perform different actions based on the first condition that evaluates to true.<\/p>\n<ul class=\"wp-block-list\">\n<li><strong>switch statement:<\/strong> The <code>switch<\/code> statement provides a way to perform different actions based on multiple possible values of a single expression. It simplifies writing multiple <code>if...else if<\/code> statements. Here&#8217;s an example:<\/li>\n<\/ul>\n<pre class=\"brush:js\">\nswitch (expression) {\n  case value1:\n    \/\/ code to be executed if expression matches value1\n    break;\n  case value2:\n    \/\/ code to be executed if expression matches value2\n    break;\n  default:\n    \/\/ code to be executed if expression doesn't match any case\n    break;\n}\n<\/pre>\n<p>Here&#8217;s an example of using the <code>switch<\/code> statement:<\/p>\n<pre class=\"brush:js\">\nlet day = \"Monday\";\n\nswitch (day) {\n  case \"Monday\":\n    console.log(\"It's the first day of the week.\");\n    break;\n  case \"Tuesday\":\n    console.log(\"It's the second day of the week.\");\n    break;\n  case \"Wednesday\":\n    console.log(\"It's the third day of the week.\");\n    break;\n  case \"Thursday\":\n  case \"Friday\":\n    console.log(\"It's a weekday.\");\n    break;\n  case \"Saturday\":\n  case \"Sunday\":\n    console.log(\"It's a weekend day.\");\n    break;\n  default:\n    console.log(\"Invalid day.\");\n}\n\nconsole.log(\"End of program.\");\n<\/pre>\n<p>In this example, we have a variable <code>day<\/code> that represents a day of the week. The <code>switch<\/code> statement evaluates the value of <code>day<\/code> and executes the code block associated with the matching case.<\/p>\n<ul class=\"wp-block-list\">\n<li>If <code>day<\/code> is &#8220;Monday&#8221;, the code block inside the <code>case \"Monday\":<\/code> will be executed, printing &#8220;It&#8217;s the first day of the week.&#8221; to the console.<\/li>\n<li>If <code>day<\/code> is &#8220;Tuesday&#8221;, the code block inside the <code>case \"Tuesday\":<\/code> will be executed, printing &#8220;It&#8217;s the second day of the week.&#8221; to the console.<\/li>\n<li>Similarly, for &#8220;Wednesday&#8221;, &#8220;Thursday&#8221;, and &#8220;Friday&#8221;, the corresponding code blocks will be executed.<\/li>\n<li>If <code>day<\/code> is &#8220;Saturday&#8221; or &#8220;Sunday&#8221;, the code block inside the <code>case \"Saturday\":<\/code> will be executed. Since there is no specific case for Sunday, the code block for <code>case \"Sunday\":<\/code> will also be executed. It will print &#8220;It&#8217;s a weekend day.&#8221; to the console.<\/li>\n<li>If <code>day<\/code> doesn&#8217;t match any of the defined cases, the code block inside the <code>default:<\/code> will be executed, printing &#8220;Invalid day.&#8221; to the console.<\/li>\n<\/ul>\n<p>After executing the appropriate code block, the program continues to the next line after the <code>switch<\/code> statement, and &#8220;End of program.&#8221; will be printed to the console.<\/p>\n<p>The <code>switch<\/code> statement allows you to perform different actions based on multiple possible values of a single expression. It simplifies the code by avoiding multiple <code>if...else if<\/code> statements when comparing against multiple cases.<\/p>\n<p>Conditional statements can be combined, nested, and used in various ways to handle complex decision-making scenarios. The conditions in conditionals are typically evaluated using comparison operators (e.g., <code>==<\/code>, <code>===<\/code>, <code>!=<\/code>, <code>!==<\/code>, <code>&lt;<\/code>, <code>&gt;<\/code>, <code>&lt;=<\/code>, <code>&gt;=<\/code>) or logical operators (e.g., <code>&amp;&amp;<\/code> for logical AND, <code>||<\/code> for logical OR, <code>!<\/code> for logical NOT).<\/p>\n<p>By leveraging conditional statements, you can control the flow of your program, handle different inputs or scenarios, validate data, and create dynamic behaviors in your code. They are an essential tool for implementing branching logic and enabling your code to make informed decisions based on specific conditions.<\/p>\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n<p>In conclusion, conditional statements are fundamental constructs in programming languages that allow you to make decisions and execute different blocks of code based on specific conditions. They are essential for creating dynamic and flexible programs. Here&#8217;s a summary of the key points discussed:<\/p>\n<ul class=\"wp-block-list\">\n<li>Conditional statements, such as <code>if<\/code>, <code>if...else<\/code>, <code>if...else if...else<\/code>, and <code>switch<\/code>, enable your code to respond to different conditions and execute different code blocks accordingly.<\/li>\n<li>Comparison operators (<code>==<\/code>, <code>!=<\/code>, <code>===<\/code>, <code>!==<\/code>, <code>&lt;<\/code>, <code>&gt;<\/code>, <code>&lt;=<\/code>, <code>&gt;=<\/code>) are used to evaluate conditions based on the comparison of values.<\/li>\n<li>Logical operators (<code>&amp;&amp;<\/code>, <code>||<\/code>, <code>!<\/code>) are used to combine multiple conditions and create more complex expressions.<\/li>\n<li>The ternary operator (<code>condition ? expression1 : expression2<\/code>) provides a concise way to write conditional expressions with two possible outcomes.<\/li>\n<li>The <code>switch<\/code> statement allows you to compare a single value against multiple cases and execute different code blocks based on the matching case.<\/li>\n<li>Conditional statements can be nested, combined, and used in various ways to handle complex decision-making scenarios in your programs.<\/li>\n<\/ul>\n<p>By leveraging conditional statements effectively, you can control the flow of your code, handle different scenarios, validate data, and create dynamic behaviors. Understanding and applying conditional statements correctly is crucial for writing robust and reliable code.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Conditional statements, also known as conditionals, are an essential part of programming languages. They allow you to make decisions and execute different blocks of code based on certain conditions. Conditional statements enable your code to respond dynamically to different scenarios, making your programs more flexible and powerful. In general, conditional statements evaluate a condition or &hellip;<\/p>\n","protected":false},"author":608,"featured_media":20900,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1879],"tags":[],"class_list":["post-117593","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-javascript"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Conditionals In JavaScript - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"Conditional statements, also known as conditionals, are an essential part of programming languages. They allow you to make decisions and execute different\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.javacodegeeks.com\/2023\/05\/conditionals-in-javascript.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Conditionals In JavaScript - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"Conditional statements, also known as conditionals, are an essential part of programming languages. They allow you to make decisions and execute different\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.javacodegeeks.com\/2023\/05\/conditionals-in-javascript.html\" \/>\n<meta property=\"og:site_name\" content=\"Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2023-05-31T08:51:11+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-05-31T08:51:13+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2014\/01\/javascript-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Java Code Geeks\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Java Code Geeks\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"9 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2023\\\/05\\\/conditionals-in-javascript.html#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2023\\\/05\\\/conditionals-in-javascript.html\"},\"author\":{\"name\":\"Java Code Geeks\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/bf3dde44bc42cc87337f272f39be46cc\"},\"headline\":\"Conditionals In JavaScript\",\"datePublished\":\"2023-05-31T08:51:11+00:00\",\"dateModified\":\"2023-05-31T08:51:13+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2023\\\/05\\\/conditionals-in-javascript.html\"},\"wordCount\":1563,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2023\\\/05\\\/conditionals-in-javascript.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2014\\\/01\\\/javascript-logo.jpg\",\"articleSection\":[\"JavaScript\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2023\\\/05\\\/conditionals-in-javascript.html#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2023\\\/05\\\/conditionals-in-javascript.html\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2023\\\/05\\\/conditionals-in-javascript.html\",\"name\":\"Conditionals In JavaScript - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2023\\\/05\\\/conditionals-in-javascript.html#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2023\\\/05\\\/conditionals-in-javascript.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2014\\\/01\\\/javascript-logo.jpg\",\"datePublished\":\"2023-05-31T08:51:11+00:00\",\"dateModified\":\"2023-05-31T08:51:13+00:00\",\"description\":\"Conditional statements, also known as conditionals, are an essential part of programming languages. They allow you to make decisions and execute different\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2023\\\/05\\\/conditionals-in-javascript.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2023\\\/05\\\/conditionals-in-javascript.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2023\\\/05\\\/conditionals-in-javascript.html#primaryimage\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2014\\\/01\\\/javascript-logo.jpg\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2014\\\/01\\\/javascript-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2023\\\/05\\\/conditionals-in-javascript.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Web Development\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/web-development\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"JavaScript\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/web-development\\\/javascript\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Conditionals In JavaScript\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Developers Resource Center\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.javacodegeeks.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/javacodegeeks\",\"https:\\\/\\\/x.com\\\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/bf3dde44bc42cc87337f272f39be46cc\",\"name\":\"Java Code Geeks\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2015\\\/02\\\/Java-Code-Geeks-96x96.jpg\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2015\\\/02\\\/Java-Code-Geeks-96x96.jpg\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2015\\\/02\\\/Java-Code-Geeks-96x96.jpg\",\"caption\":\"Java Code Geeks\"},\"description\":\"JCGs (Java Code Geeks) is an independent online community focused on creating the ultimate Java to Java developers resource center; targeted at the technical architect, technical team lead (senior developer), project manager and junior developers alike. JCGs serve the Java, SOA, Agile and Telecom communities with daily news written by domain experts, articles, tutorials, reviews, announcements, code snippets and open source projects.\",\"sameAs\":[\"http:\\\/\\\/www.javacodegeeks.com\\\/\",\"https:\\\/\\\/www.facebook.com\\\/javacodegeeks\",\"https:\\\/\\\/www.linkedin.com\\\/groups\\\/Java-Code-Geeks-3810709\",\"https:\\\/\\\/x.com\\\/javacodegeeks\"],\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/author\\\/jcg\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Conditionals In JavaScript - Java Code Geeks","description":"Conditional statements, also known as conditionals, are an essential part of programming languages. They allow you to make decisions and execute different","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:\/\/www.javacodegeeks.com\/2023\/05\/conditionals-in-javascript.html","og_locale":"en_US","og_type":"article","og_title":"Conditionals In JavaScript - Java Code Geeks","og_description":"Conditional statements, also known as conditionals, are an essential part of programming languages. They allow you to make decisions and execute different","og_url":"https:\/\/www.javacodegeeks.com\/2023\/05\/conditionals-in-javascript.html","og_site_name":"Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_author":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2023-05-31T08:51:11+00:00","article_modified_time":"2023-05-31T08:51:13+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2014\/01\/javascript-logo.jpg","type":"image\/jpeg"}],"author":"Java Code Geeks","twitter_card":"summary_large_image","twitter_creator":"@javacodegeeks","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Java Code Geeks","Est. reading time":"9 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.javacodegeeks.com\/2023\/05\/conditionals-in-javascript.html#article","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/2023\/05\/conditionals-in-javascript.html"},"author":{"name":"Java Code Geeks","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/bf3dde44bc42cc87337f272f39be46cc"},"headline":"Conditionals In JavaScript","datePublished":"2023-05-31T08:51:11+00:00","dateModified":"2023-05-31T08:51:13+00:00","mainEntityOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2023\/05\/conditionals-in-javascript.html"},"wordCount":1563,"commentCount":0,"publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2023\/05\/conditionals-in-javascript.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2014\/01\/javascript-logo.jpg","articleSection":["JavaScript"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.javacodegeeks.com\/2023\/05\/conditionals-in-javascript.html#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.javacodegeeks.com\/2023\/05\/conditionals-in-javascript.html","url":"https:\/\/www.javacodegeeks.com\/2023\/05\/conditionals-in-javascript.html","name":"Conditionals In JavaScript - Java Code Geeks","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2023\/05\/conditionals-in-javascript.html#primaryimage"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2023\/05\/conditionals-in-javascript.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2014\/01\/javascript-logo.jpg","datePublished":"2023-05-31T08:51:11+00:00","dateModified":"2023-05-31T08:51:13+00:00","description":"Conditional statements, also known as conditionals, are an essential part of programming languages. They allow you to make decisions and execute different","breadcrumb":{"@id":"https:\/\/www.javacodegeeks.com\/2023\/05\/conditionals-in-javascript.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.javacodegeeks.com\/2023\/05\/conditionals-in-javascript.html"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/2023\/05\/conditionals-in-javascript.html#primaryimage","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2014\/01\/javascript-logo.jpg","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2014\/01\/javascript-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/www.javacodegeeks.com\/2023\/05\/conditionals-in-javascript.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Web Development","item":"https:\/\/www.javacodegeeks.com\/category\/web-development"},{"@type":"ListItem","position":3,"name":"JavaScript","item":"https:\/\/www.javacodegeeks.com\/category\/web-development\/javascript"},{"@type":"ListItem","position":4,"name":"Conditionals In JavaScript"}]},{"@type":"WebSite","@id":"https:\/\/www.javacodegeeks.com\/#website","url":"https:\/\/www.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Developers Resource Center","publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/www.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/bf3dde44bc42cc87337f272f39be46cc","name":"Java Code Geeks","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2015\/02\/Java-Code-Geeks-96x96.jpg","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2015\/02\/Java-Code-Geeks-96x96.jpg","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2015\/02\/Java-Code-Geeks-96x96.jpg","caption":"Java Code Geeks"},"description":"JCGs (Java Code Geeks) is an independent online community focused on creating the ultimate Java to Java developers resource center; targeted at the technical architect, technical team lead (senior developer), project manager and junior developers alike. JCGs serve the Java, SOA, Agile and Telecom communities with daily news written by domain experts, articles, tutorials, reviews, announcements, code snippets and open source projects.","sameAs":["http:\/\/www.javacodegeeks.com\/","https:\/\/www.facebook.com\/javacodegeeks","https:\/\/www.linkedin.com\/groups\/Java-Code-Geeks-3810709","https:\/\/x.com\/javacodegeeks"],"url":"https:\/\/www.javacodegeeks.com\/author\/jcg"}]}},"_links":{"self":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/117593","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/users\/608"}],"replies":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=117593"}],"version-history":[{"count":0,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/117593\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media\/20900"}],"wp:attachment":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=117593"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=117593"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=117593"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}