{"id":95705,"date":"2022-09-03T05:19:26","date_gmt":"2022-09-03T03:19:26","guid":{"rendered":"https:\/\/rmarketingdigital.com\/javascript\/estructuras-de-control-en-javascript\/"},"modified":"2020-12-06T17:48:34","modified_gmt":"2020-12-06T20:48:34","slug":"estructuras-de-control-en-javascript","status":"publish","type":"post","link":"https:\/\/rmarketingdigital.com\/en\/javascript\/estructuras-de-control-en-javascript\/","title":{"rendered":"Control structures in JavaScript"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_86 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewbox=\"0 0 24 24\" version=\"1.2\" baseprofile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/rmarketingdigital.com\/en\/javascript\/estructuras-de-control-en-javascript\/#La-declaracion-%C2%ABif%C2%BB\" >The &quot;if&quot; statement<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/rmarketingdigital.com\/en\/javascript\/estructuras-de-control-en-javascript\/#Conversion-booleana\" >Boolean conversion<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/rmarketingdigital.com\/en\/javascript\/estructuras-de-control-en-javascript\/#La-clausula-%C2%ABelse%C2%BB\" >The &quot;else&quot; clause<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/rmarketingdigital.com\/en\/javascript\/estructuras-de-control-en-javascript\/#Varias-condiciones-%E2%80%9Csi-no%E2%80%9D\" >Various conditions: &quot;yes no&quot;<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/rmarketingdigital.com\/en\/javascript\/estructuras-de-control-en-javascript\/#Operador-ternario-%E2%80%98\" >Ternary operator &#039;?&#039;<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/rmarketingdigital.com\/en\/javascript\/estructuras-de-control-en-javascript\/#Multiples-%E2%80%98\" >Multiple &#039;?&#039;<\/a><ul class='ez-toc-list-level-4' ><li class='ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/rmarketingdigital.com\/en\/javascript\/estructuras-de-control-en-javascript\/#Uso-no-tradicional-de-%E2%80%98\" >Non-traditional use of &#039;?&#039;<\/a><\/li><\/ul><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n<div itemprop=\"articleBody\">\n<p>Many times, both in JavaScript and in other programming languages we need to perform different actions based on a condition.<span id=\"more-34\"\/><\/p>\n<p>There is an if statement for that and also the conditional (ternary) operator for evaluating the conditional, which we will refer to as the &quot;question mark&quot; operator. <strong>?<\/strong> For simplicity.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"La-declaracion-%C2%ABif%C2%BB\"><\/span>The &quot;if&quot; statement<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>The if statement gets a condition, evaluates it, and if the result is <em>true<\/em> (true), execute the code, and if not, no.<\/p>\n<p>For example:<\/p>\n<pre data-enlighter-language=\"php\" class=\"EnlighterJSRAW\">\/\/ What year was the ECMAScript-2015 specification published? &#039; \/\/ Answer: in 2015 let year = 2015; if (year == 2015) alert (&#039;It was published in the year 2015&#039;);\n<\/pre>\n<p>In the example above, the condition is a simple equality check: <strong>years == 2015<\/strong>, but it can be much more complex.<\/p>\n<p>If there is more than one statement to execute, we have to wrap our code block in braces:<\/p>\n<pre data-enlighter-language=\"php\" class=\"EnlighterJSRAW\">if (years == 2015) {alert (&quot;You are correct!&quot;); alert (&quot;You are extremely smart!&quot;); }<\/pre>\n<p>It is recommended to wrap the code block\u00a0<strong>if<\/strong> with keys <strong>{}<\/strong> each time, even if there is only one statement. That improves readability.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Conversion-booleana\"><\/span>Boolean conversion<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>The <strong>if statement (\u2026)<\/strong> evaluates the expression in parentheses and converts it to the Boolean type.<\/p>\n<ul>\n<li>A number 0, an empty string \u00bb\u00ab, null, undefined, and NaN is converted to <em>false<\/em>. That is why they are called &quot;false&quot; values.<\/li>\n<li>Other values become <strong style=\"font-size: 1rem;\">true<\/strong><span style=\"font-size: 1rem;\">, so they are called &quot;truth.&quot;<\/span><\/li>\n<\/ul>\n<p>So the code under this condition would never run:<\/p>\n<pre data-enlighter-language=\"php\" class=\"EnlighterJSRAW\">if (0) {\/\/ 0 is false ...} ... And inside this condition - it always works: if (1) {\/\/ 1 is true ...}\n<\/pre>\n<p>We can also pass a pre-evaluated Boolean value to<strong> if<\/strong>, as here:<\/p>\n<pre data-enlighter-language=\"php\" class=\"EnlighterJSRAW\">let cond = (years == 2015); \/\/ equality evaluates to true or false if (cond) {...}\n<\/pre>\n<h3><span class=\"ez-toc-section\" id=\"La-clausula-%C2%ABelse%C2%BB\"><\/span>The &quot;else&quot; clause<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>The declaration <strong>if<\/strong> can contain a block <strong>Else<\/strong> optional. It runs when the condition is wrong.<\/p>\n<p>For example:<\/p>\n<pre data-enlighter-language=\"php\" class=\"EnlighterJSRAW\">let age = 16; if (age&gt; = 18) {alert (&#039;You are already of legal age&#039;); } else {alert (&#039;you are a minor&#039;); \/\/ Since age is equal to 16, the if block will be completely skipped and immediately jump to the else}\n<\/pre>\n<h3><span class=\"ez-toc-section\" id=\"Varias-condiciones-%E2%80%9Csi-no%E2%80%9D\"><\/span>Various conditions: &quot;yes no&quot;<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Sometimes we would like to test several variants of a condition. There is a clause<strong> else if<\/strong> For that.<\/p>\n<p>For example:<\/p>\n<pre data-enlighter-language=\"php\" class=\"EnlighterJSRAW\">let year = prompt (&#039;In what year was the ECMAScript-2015 specification published?&#039;, &#039;&#039;); if (year &lt;2015) {alert (&#039;Too soon ...&#039;); } else if (year&gt; 2015) {alert (&#039;Too late&#039;); } else {alert (&#039;Exact!&#039;); }\n<\/pre>\n<p>In the above code JavaScript first checks <strong>year &lt;2015<\/strong>. If it is false, it goes to the next condition <strong>year&gt; 2015\u00a0<\/strong>and otherwise it shows the last alert.<\/p>\n<p>There may be more else if blocks. The ending else is optional.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Operador-ternario-%E2%80%98\"><\/span>Ternary operator &#039;?&#039;<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Sometimes we need to assign a variable depending on a condition.<\/p>\n<p>For example:<\/p>\n<pre data-enlighter-language=\"php\" class=\"EnlighterJSRAW\">let AccessAllowed; let age = prompt (&#039;How old are you?&#039;, &#039;&#039;); if (age&gt; 18) {AllowedAccess = true; } else {AllowedAccess = false; } alert (AccessAllowed);\n<\/pre>\n<p>The operator called &quot;ternary&quot; or &quot;question mark&quot; allows us to do it in a shorter and easier way.<\/p>\n<p>The operator is represented by a question mark <strong>?<\/strong>. The formal term &quot;ternary&quot; means that the operator has three operands. Actually, it is the only operator in JavaScript that has so many.<\/p>\n<p>The syntax is:<\/p>\n<pre data-enlighter-language=\"php\" class=\"EnlighterJSRAW\">let result = condition? value1: value2\n<\/pre>\n<p>Is evaluated <strong>condition<\/strong>, if it is true then <strong>value1<\/strong> is returned, otherwise - <strong>value2<\/strong>.<\/p>\n<p>For example:<\/p>\n<pre data-enlighter-language=\"php\" class=\"EnlighterJSRAW\">let AllowedAccess = (age&gt; 18)? true: false;\n<\/pre>\n<p>Technically, we can omit parentheses around <strong>age&gt; 18<\/strong>. The question mark operator has a low priority. Runs after comparison <strong>&gt;<\/strong>, so we will do the same:<\/p>\n<pre data-enlighter-language=\"php\" class=\"EnlighterJSRAW\">\/\/ the relational operator &quot;age&gt; 18&quot; executes first anyway \/\/ (no need to wrap it in parentheses) let AllowedAccess = age&gt; 18? true: false;<\/pre>\n<p>But the parentheses make the code more readable, so it is recommended to use them.<\/p>\n<p>Keep in mind:<br \/>In the example above, it is possible to evade the question mark operator, because the comparison itself returns true \/ false:<\/p>\n<pre data-enlighter-language=\"php\" class=\"EnlighterJSRAW\">\/\/ the same let AllowedAccess = age&gt; 18;\n<\/pre>\n<h3><span class=\"ez-toc-section\" id=\"Multiples-%E2%80%98\"><\/span>Multiple &#039;?&#039;<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>A sequence of question mark operators? allows to return a value that depends on more than one condition.<\/p>\n<p>For example:<\/p>\n<pre data-enlighter-language=\"php\" class=\"EnlighterJSRAW\">let age = prompt (&#039;age?&#039;, 18); let message = (age &lt;3)? &#039;Hi chic@!&#039; : (age &lt;18)? &#039;Hello!&#039; : (age &lt;100)? &#039;Greetings !&#039; : &#039;What an unusual age! &#039;; alert (message);<\/pre>\n<p>It can be difficult at first to understand what is going on. But after a more detailed analysis, we can see that it is just an ordinary sequence of tests.<\/p>\n<p>The first question mark checks if <strong>age &lt;3<\/strong>.<br \/>If true - it returns &#039;Hello, chic @!&#039;, Otherwise - it goes after the colon &quot;:&quot; and looks for age &lt;18.<br \/>If that&#039;s true, it returns &#039;Hello!&#039;, Otherwise, it goes after the colon &#039;:&#039; and checks for age &lt;100.<br \/>If that&#039;s true, it returns &#039;Greetings!&#039;, Otherwise, it goes after the last colon &#039;:&#039; and returns &#039;What an unusual age!&#039;.<\/p>\n<p>Here I show you the same logic using if..else:<\/p>\n<pre data-enlighter-language=\"php\" class=\"EnlighterJSRAW\">if (age &lt;3) {message = &#039;Hello, chic @!&#039;; } else if (age &lt;18) {message = &#039;Hello!&#039;; } else if (age &lt;100) {message = &#039;Greetings!&#039;; } else {message = &#039;What an unusual age!&#039;; }\n<\/pre>\n<h4><span class=\"ez-toc-section\" id=\"Uso-no-tradicional-de-%E2%80%98\"><\/span>Non-traditional use of &#039;?&#039;<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p>Sometimes the question mark? is used as a replacement for if:<\/p>\n<pre data-enlighter-language=\"php\" class=\"EnlighterJSRAW\">let company = prompt (&#039;What company created JavaScript?&#039;, &#039;&#039;); (company == &#039;Netscape&#039;)? alert (&#039;Correct!&#039;): alert (&#039;Incorrect.&#039;);\n<\/pre>\n<p>Depending on the condition <strong>company == &#039;Netscape&#039;<\/strong>, the first or the second back? they run and display the alert.<\/p>\n<p>We don&#039;t assign a result to a variable here. The idea is to run different code depending on the condition.<\/p>\n<p>Using the question mark operator in this way is not recommended.<\/p>\n<p>The notation appears to be shorter than if, which appeals to some programmers. But it is less readable.<\/p>\n<p>Here is the same if code for comparison:<\/p>\n<pre data-enlighter-language=\"php\" class=\"EnlighterJSRAW\">let company = prompt (&#039;What company created JavaScript?&#039;, &#039;&#039;); if (company == &#039;Netscape&#039;) {alert (&#039;Correct!&#039;); } else {alert (&#039;Incorrect.&#039;); }\n<\/pre>\n<p>Our eyes scan the code vertically. Constructs that span multiple lines are easier to understand than a long horizontal instruction set.<\/p>\n<p>The idea of a question mark? is to return one or the other value depending on the condition. Please use it for exactly that.<\/p>\n<\/p><\/div>","protected":false},"excerpt":{"rendered":"<p>Muchas veces, tanto en JavaScript como en otros lenguajes de programaci\u00f3n necesitamos realizar diferentes acciones basadas en una condici\u00f3n. Hay una declaraci\u00f3n\u00a0if para eso y tambi\u00e9n el operador condicional (ternario)&#8230;<\/p>","protected":false},"author":1,"featured_media":95706,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1374],"tags":[],"class_list":["post-95705","post","type-post","status-publish","format-standard","has-post-thumbnail","category-javascript"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.0 (Yoast SEO v28.2) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Estructuras de control en JavaScript - R Marketing Digital<\/title>\n<meta name=\"description\" content=\"Muchas veces, tanto en JavaScript como en otros lenguajes de programaci\u00f3n necesitamos realizar diferentes acciones basadas en una condici\u00f3n. Hay una\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/rmarketingdigital.com\/en\/javascript\/estructuras-de-control-en-javascript\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Estructuras de control en JavaScript\" \/>\n<meta property=\"og:description\" content=\"Muchas veces, tanto en JavaScript como en otros lenguajes de programaci\u00f3n necesitamos realizar diferentes acciones basadas en una condici\u00f3n. Hay una\" \/>\n<meta property=\"og:url\" content=\"https:\/\/rmarketingdigital.com\/en\/javascript\/estructuras-de-control-en-javascript\/\" \/>\n<meta property=\"og:site_name\" content=\"R Marketing Digital\" \/>\n<meta property=\"article:published_time\" content=\"2022-09-03T03:19:26+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/rmarketingdigital.com\/wp-content\/uploads\/2020\/12\/Diseno-sin-titulo-14-1399280.png\" \/>\n\t<meta property=\"og:image:width\" content=\"810\" \/>\n\t<meta property=\"og:image:height\" content=\"450\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"R Marketing Digital\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/rmarketingdigital.com\\\/javascript\\\/estructuras-de-control-en-javascript\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/rmarketingdigital.com\\\/javascript\\\/estructuras-de-control-en-javascript\\\/\"},\"author\":{\"name\":\"R Marketing Digital\",\"@id\":\"https:\\\/\\\/rmarketingdigital.com\\\/#\\\/schema\\\/person\\\/7c0d9782b2977b840b3740f00c69a73e\"},\"headline\":\"Estructuras de control en JavaScript\",\"datePublished\":\"2022-09-03T03:19:26+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/rmarketingdigital.com\\\/javascript\\\/estructuras-de-control-en-javascript\\\/\"},\"wordCount\":793,\"image\":{\"@id\":\"https:\\\/\\\/rmarketingdigital.com\\\/javascript\\\/estructuras-de-control-en-javascript\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/rmarketingdigital.com\\\/wp-content\\\/uploads\\\/2020\\\/12\\\/Diseno-sin-titulo-14-1399280.png\",\"articleSection\":[\"Javascript\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/rmarketingdigital.com\\\/javascript\\\/estructuras-de-control-en-javascript\\\/\",\"url\":\"https:\\\/\\\/rmarketingdigital.com\\\/javascript\\\/estructuras-de-control-en-javascript\\\/\",\"name\":\"Estructuras de control en JavaScript - R Marketing Digital\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/rmarketingdigital.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/rmarketingdigital.com\\\/javascript\\\/estructuras-de-control-en-javascript\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/rmarketingdigital.com\\\/javascript\\\/estructuras-de-control-en-javascript\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/rmarketingdigital.com\\\/wp-content\\\/uploads\\\/2020\\\/12\\\/Diseno-sin-titulo-14-1399280.png\",\"datePublished\":\"2022-09-03T03:19:26+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/rmarketingdigital.com\\\/#\\\/schema\\\/person\\\/7c0d9782b2977b840b3740f00c69a73e\"},\"description\":\"Muchas veces, tanto en JavaScript como en otros lenguajes de programaci\u00f3n necesitamos realizar diferentes acciones basadas en una condici\u00f3n. Hay una\",\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/rmarketingdigital.com\\\/javascript\\\/estructuras-de-control-en-javascript\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/rmarketingdigital.com\\\/javascript\\\/estructuras-de-control-en-javascript\\\/#primaryimage\",\"url\":\"https:\\\/\\\/rmarketingdigital.com\\\/wp-content\\\/uploads\\\/2020\\\/12\\\/Diseno-sin-titulo-14-1399280.png\",\"contentUrl\":\"https:\\\/\\\/rmarketingdigital.com\\\/wp-content\\\/uploads\\\/2020\\\/12\\\/Diseno-sin-titulo-14-1399280.png\",\"width\":810,\"height\":450,\"caption\":\"diseno-sin-titulo-14-1399280-8064508-png\"},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/rmarketingdigital.com\\\/#website\",\"url\":\"https:\\\/\\\/rmarketingdigital.com\\\/\",\"name\":\"R Marketing Digital\",\"description\":\"Agencia SEO | Publicidad redes sociales | Community Management\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/rmarketingdigital.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/rmarketingdigital.com\\\/#\\\/schema\\\/person\\\/7c0d9782b2977b840b3740f00c69a73e\",\"name\":\"R Marketing Digital\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/c5599c203e0120b8ccbff4666af86f35f9b3dcad468a8bc6295313a3964a80be?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/c5599c203e0120b8ccbff4666af86f35f9b3dcad468a8bc6295313a3964a80be?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/c5599c203e0120b8ccbff4666af86f35f9b3dcad468a8bc6295313a3964a80be?s=96&d=mm&r=g\",\"caption\":\"R Marketing Digital\"}}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Estructuras de control en JavaScript - R Marketing Digital","description":"Many times, both in JavaScript and in other programming languages we need to perform different actions based on a condition. There is a","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:\/\/rmarketingdigital.com\/en\/javascript\/estructuras-de-control-en-javascript\/","og_locale":"en_US","og_type":"article","og_title":"Estructuras de control en JavaScript","og_description":"Muchas veces, tanto en JavaScript como en otros lenguajes de programaci\u00f3n necesitamos realizar diferentes acciones basadas en una condici\u00f3n. Hay una","og_url":"https:\/\/rmarketingdigital.com\/en\/javascript\/estructuras-de-control-en-javascript\/","og_site_name":"R Marketing Digital","article_published_time":"2022-09-03T03:19:26+00:00","og_image":[{"width":810,"height":450,"url":"https:\/\/rmarketingdigital.com\/wp-content\/uploads\/2020\/12\/Diseno-sin-titulo-14-1399280.png","type":"image\/png"}],"author":"R Marketing Digital","twitter_card":"summary_large_image","schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/rmarketingdigital.com\/javascript\/estructuras-de-control-en-javascript\/#article","isPartOf":{"@id":"https:\/\/rmarketingdigital.com\/javascript\/estructuras-de-control-en-javascript\/"},"author":{"name":"R Marketing Digital","@id":"https:\/\/rmarketingdigital.com\/#\/schema\/person\/7c0d9782b2977b840b3740f00c69a73e"},"headline":"Estructuras de control en JavaScript","datePublished":"2022-09-03T03:19:26+00:00","mainEntityOfPage":{"@id":"https:\/\/rmarketingdigital.com\/javascript\/estructuras-de-control-en-javascript\/"},"wordCount":793,"image":{"@id":"https:\/\/rmarketingdigital.com\/javascript\/estructuras-de-control-en-javascript\/#primaryimage"},"thumbnailUrl":"https:\/\/rmarketingdigital.com\/wp-content\/uploads\/2020\/12\/Diseno-sin-titulo-14-1399280.png","articleSection":["Javascript"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/rmarketingdigital.com\/javascript\/estructuras-de-control-en-javascript\/","url":"https:\/\/rmarketingdigital.com\/javascript\/estructuras-de-control-en-javascript\/","name":"Estructuras de control en JavaScript - R Marketing Digital","isPartOf":{"@id":"https:\/\/rmarketingdigital.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/rmarketingdigital.com\/javascript\/estructuras-de-control-en-javascript\/#primaryimage"},"image":{"@id":"https:\/\/rmarketingdigital.com\/javascript\/estructuras-de-control-en-javascript\/#primaryimage"},"thumbnailUrl":"https:\/\/rmarketingdigital.com\/wp-content\/uploads\/2020\/12\/Diseno-sin-titulo-14-1399280.png","datePublished":"2022-09-03T03:19:26+00:00","author":{"@id":"https:\/\/rmarketingdigital.com\/#\/schema\/person\/7c0d9782b2977b840b3740f00c69a73e"},"description":"Many times, both in JavaScript and in other programming languages we need to perform different actions based on a condition. There is a","inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/rmarketingdigital.com\/javascript\/estructuras-de-control-en-javascript\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/rmarketingdigital.com\/javascript\/estructuras-de-control-en-javascript\/#primaryimage","url":"https:\/\/rmarketingdigital.com\/wp-content\/uploads\/2020\/12\/Diseno-sin-titulo-14-1399280.png","contentUrl":"https:\/\/rmarketingdigital.com\/wp-content\/uploads\/2020\/12\/Diseno-sin-titulo-14-1399280.png","width":810,"height":450,"caption":"diseno-sin-titulo-14-1399280-8064508-png"},{"@type":"WebSite","@id":"https:\/\/rmarketingdigital.com\/#website","url":"https:\/\/rmarketingdigital.com\/","name":"R Digital Marketing","description":"SEO Agency | Advertising social networks | Community Management","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/rmarketingdigital.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/rmarketingdigital.com\/#\/schema\/person\/7c0d9782b2977b840b3740f00c69a73e","name":"R Digital Marketing","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/c5599c203e0120b8ccbff4666af86f35f9b3dcad468a8bc6295313a3964a80be?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/c5599c203e0120b8ccbff4666af86f35f9b3dcad468a8bc6295313a3964a80be?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/c5599c203e0120b8ccbff4666af86f35f9b3dcad468a8bc6295313a3964a80be?s=96&d=mm&r=g","caption":"R Marketing Digital"}}]}},"_links":{"self":[{"href":"https:\/\/rmarketingdigital.com\/en\/wp-json\/wp\/v2\/posts\/95705","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/rmarketingdigital.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/rmarketingdigital.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/rmarketingdigital.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/rmarketingdigital.com\/en\/wp-json\/wp\/v2\/comments?post=95705"}],"version-history":[{"count":0,"href":"https:\/\/rmarketingdigital.com\/en\/wp-json\/wp\/v2\/posts\/95705\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/rmarketingdigital.com\/en\/wp-json\/wp\/v2\/media\/95706"}],"wp:attachment":[{"href":"https:\/\/rmarketingdigital.com\/en\/wp-json\/wp\/v2\/media?parent=95705"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/rmarketingdigital.com\/en\/wp-json\/wp\/v2\/categories?post=95705"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/rmarketingdigital.com\/en\/wp-json\/wp\/v2\/tags?post=95705"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}