{"id":95682,"date":"2022-09-10T20:05:16","date_gmt":"2022-09-10T18:05:16","guid":{"rendered":"https:\/\/rmarketingdigital.com\/javascript\/funciones-en-javascript\/"},"modified":"2020-12-06T14:47:18","modified_gmt":"2020-12-06T17:47:18","slug":"funciones-en-javascript","status":"publish","type":"post","link":"https:\/\/rmarketingdigital.com\/en\/javascript\/funciones-en-javascript\/","title":{"rendered":"Functions 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\/funciones-en-javascript\/#Declaracion-de-funciones\" >Declaration of functions<\/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\/funciones-en-javascript\/#Variables-locales\" >Local variables<\/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\/funciones-en-javascript\/#Variables-externas\" >External variables<\/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\/funciones-en-javascript\/#Variables-globales\" >Global variables<\/a><ul class='ez-toc-list-level-4' ><li class='ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/rmarketingdigital.com\/en\/javascript\/funciones-en-javascript\/#Parametros\" >Parameters<\/a><\/li><\/ul><\/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\/funciones-en-javascript\/#Valores-predeterminados\" >Predetermined values<\/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\/funciones-en-javascript\/#Parametros-por-defecto-de-estilo-antiguo\" >Old style default parameters<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/rmarketingdigital.com\/en\/javascript\/funciones-en-javascript\/#El-operador\" >The operator ||:<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n<div itemprop=\"articleBody\">\n<p>Very often we need to perform a similar action in many places in the script. For example, we must show an attractive message when a visitor starts <span id=\"more-40\"\/>session, log out and maybe somewhere else.<\/p>\n<p>Functions are the main &quot;building blocks&quot; of the program. They allow the code to be called many times without repetition.<\/p>\n<p>We have already seen examples of built-in functions, such as <strong>alert (message)<\/strong>, <strong>prompt (message, default)\u00a0<\/strong>and <strong>confirm (question)<\/strong>. But we can also create our own functions.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Declaracion-de-funciones\"><\/span>Declaration of functions<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>To create a function we can use a function declaration.<\/p>\n<p>Does it look like this:<\/p>\n<pre data-enlighter-language=\"php\" class=\"EnlighterJSRAW\">function showMessage () {alert (&#039;Hello everyone!&#039;); }\n<\/pre>\n<p>The key word <strong>function<\/strong> comes first, then the name of the function, then a list of parameters between the parentheses (empty in the example above) and finally the code of the function, also called &quot;the body of the function&quot;, enclosed in braces.<\/p>\n<p>Our new function can be called by name: <strong>showMessage ()<\/strong>.<\/p>\n<p>For example:<\/p>\n<pre data-enlighter-language=\"php\" class=\"EnlighterJSRAW\">function showMessage {alert (&#039;Hello everyone!&#039;); } showMessage (); showMessage ();\n<\/pre>\n<p>The call <strong>showMessage ()<\/strong> executes the function code. Here we will see the message twice.<\/p>\n<p>This example clearly demonstrates one of the main purposes of functions: to avoid code duplication.<\/p>\n<p>If we ever need to change the message or the way it is displayed, simply modify the code in one place: the function that generates it.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Variables-locales\"><\/span>Local variables<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>A variable declared within a function is only visible within that function.<\/p>\n<p>For example:<\/p>\n<pre data-enlighter-language=\"php\" class=\"EnlighterJSRAW\">function showMessage () {let message = &quot;Hi, I&#039;m JavaScript!&quot;; \/\/ local variable alert (message); } showMessage (); \/\/ Hello, I am JavaScript! alert (message); \/\/ &lt;- Error! The variable is local within the function<\/pre>\n<h3><span class=\"ez-toc-section\" id=\"Variables-externas\"><\/span>External variables<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>A function can also access an external variable, for example:<\/p>\n<pre data-enlighter-language=\"php\" class=\"EnlighterJSRAW\">let username = &#039;Maria&#039;; function showMessage () {let message = &#039;Hello,&#039; + username; alert (message); } showMessage (); \/\/ Hello, Maria\n<\/pre>\n<p>The function has full access to the outer variable. You can modify it too.<\/p>\n<p>For example:<\/p>\n<pre data-enlighter-language=\"php\" class=\"EnlighterJSRAW\">let username = &#039;Maria&#039;; function showMessage () {username = &quot;Bob&quot;; \/\/ (1) changed the outer variable let message = &#039;Hello,&#039; + username; alert (message); } alert (username); \/\/ Maria before the function call showMessage (); alert (username); \/\/ Bob, the value was modified by the function\n<\/pre>\n<p>The external variable is only used if there is no local one. So an occasional modification can happen if we forget let.<\/p>\n<p>If a variable with the same name is declared inside the function, it shades the outer one. For example, in the code below, the function uses the local username. The exterior is ignored:<\/p>\n<pre data-enlighter-language=\"php\" class=\"EnlighterJSRAW\">let username = &#039;Maria&#039;; function showMessage () {let username = &quot;Bob&quot;; \/\/ declare a local variable let message = &#039;Hello,&#039; + username; \/\/ Bob alert (message); } \/\/ the function will create and use its own variable username displayMessage (); alert (username); \/\/ Maria, no changes, the function did not access the external variable<\/pre>\n<h3><span class=\"ez-toc-section\" id=\"Variables-globales\"><\/span>Global variables<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Variables declared outside of any function, such as external <strong>Username<\/strong> in the code above, they are called globals.<\/p>\n<p>Global variables are visible from any function (unless shaded by locals).<\/p>\n<p>Usually a function declares all the variables specific to its task. Global variables only store data at the project level, so when it is important that these variables are accessible from anywhere. Modern code has few or no global globes. Most of the variables reside in their functions.<\/p>\n<h4><span class=\"ez-toc-section\" id=\"Parametros\"><\/span>Parameters<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p>We can pass arbitrary data to functions using parameters (also called function arguments).<\/p>\n<p>In the following example, the function has two parameters: <b>since\u00a0<\/b>and <strong>text<\/strong>.<\/p>\n<pre data-enlighter-language=\"php\" class=\"EnlighterJSRAW\">function showMessage (from, text) {\/\/ arguments: from, text alert (from + &#039;:&#039; + text); } showMessage (&#039;Ann&#039;, &#039;Hello!&#039;); \/\/ Ann: Hi! (*) showMessage (&#039;Ann&#039;, &quot;What&#039;s wrong?&quot;); \/\/ Ann: What&#039;s up? (**)\n<\/pre>\n<p>When the function is called on lines (*) and (**), the given values are copied to the local variables <strong>since<\/strong> and <strong>text<\/strong>. Then the function uses them.<\/p>\n<p>Here&#039;s one more example: we have a variable <strong>since<\/strong> and we pass it on to the function. Please note: function changes <strong>since<\/strong>, but the change is not seen outside, because a function always gets a copy of the value:<\/p>\n<pre data-enlighter-language=\"php\" class=\"EnlighterJSRAW\">function showMessage (from, text) {from = &#039;*&#039; + from + &#039;*&#039;; \/\/ make &quot;from&quot; look better alert (from + &#039;:&#039; + text); } let from = &quot;Ann&quot;; showMessage (from, &quot;Hello&quot;); \/\/ * Ann *: Hello \/\/ the value of &quot;from&quot; is the same, the function modified a local copy alert (from); \/\/ Ann<\/pre>\n<h3><span class=\"ez-toc-section\" id=\"Valores-predeterminados\"><\/span>Predetermined values<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>If no parameter is provided, then its value becomes <strong>undefined<\/strong>.<\/p>\n<p>For example, the above-mentioned function showMessage (from, text) can be called with a single argument:<\/p>\n<pre data-enlighter-language=\"php\" class=\"EnlighterJSRAW\">showMessage (&quot;Ann&quot;);\n<\/pre>\n<p>That is not a mistake. Such a call would go out <strong>&quot;Ann: undefined&quot;.<\/strong> There is no text so it&#039;s supposed to <strong>text === undefined<\/strong>.<\/p>\n<p>If we want to use a &quot;default&quot; text in this case, we can specify it after =:<\/p>\n<pre data-enlighter-language=\"php\" class=\"EnlighterJSRAW\">function showMessage (from, text = &quot;no text&quot;) {alert (from + &quot;:&quot; + text); } showMessage (&quot;Ann&quot;); \/\/ Ann: no text Now if the text parameter is not passed, you will get the value &quot;no text&quot;\n<\/pre>\n<p>There is a string &quot;no text&quot; here, but it can be a more complex expression, which is only evaluated and assigned if the parameter is missing. Therefore, this is also possible:<\/p>\n<pre data-enlighter-language=\"php\" class=\"EnlighterJSRAW\">function showMessage (from, text = otherFunction ()) {\/\/ otherFunction () is only executed if no text has been given \/\/ its result becomes the value of the text}\n<\/pre>\n<h4><span class=\"ez-toc-section\" id=\"Parametros-por-defecto-de-estilo-antiguo\"><\/span>Old style default parameters<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p>Older editions of JavaScript did not support default parameters. So there are alternative ways to support them, which you can find mostly in old scripts.<\/p>\n<p>For example, an explicit check to be undefined:<\/p>\n<pre data-enlighter-language=\"php\" class=\"EnlighterJSRAW\">function showMessage (from, text) {if (text === undefined) {text = &#039;no text&#039;; } alert (from + &quot;:&quot; + text); } ... or\n<\/pre>\n<h3><span class=\"ez-toc-section\" id=\"El-operador\"><\/span>The operator ||:<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<pre data-enlighter-language=\"php\" class=\"EnlighterJSRAW\">function showMessage (from, text) {\/\/ if the text is false, then the text gets the &quot;default&quot; value text = text || &#039;no text&#039;; ...}<\/pre>\n<p>\nReturning a value<\/p>\n<p>A function can return a value to the calling code as a result.<\/p>\n<p>The simplest example would be a function that adds two values:<\/p>\n<pre data-enlighter-language=\"php\" class=\"EnlighterJSRAW\">function sum (a, b) {return a + b; } let result = sum (1, 2); alert (result); \/\/ 3<\/pre>\n<p>Directive <strong>return<\/strong> it can be anywhere in the function. When execution reaches it, the function stops and the value is returned to the calling code (assigned to result above).<\/p>\n<p>There may be many appearances in a single function. For example:<\/p>\n<pre data-enlighter-language=\"php\" class=\"EnlighterJSRAW\">function checkAge (age) {if (age&gt; 18) {return true; } else {return confirm (&#039;Do you have parental permission?&#039;); }} let age = prompt (&#039;How old are you?&#039;, 18); if (checkAge (age)) {alert (&#039;Access allowed&#039;); } else {alert (&#039;Access denied&#039;); }\n<\/pre>\n<p>It is possible to use <strong>return<\/strong> without a value. That causes the function to exit immediately.<\/p>\n<p>For example:<\/p>\n<pre data-enlighter-language=\"php\" class=\"EnlighterJSRAW\">function viewMovie (age) {if (! viewMovie (age)) {return; } alert (&quot;Showing you the movie&quot;); \/\/ (*) \/\/ ...}\n<\/pre>\n<p>\nIn the above code, if\u00a0<strong>verify Age (age)<\/strong> It is returned <em>false<\/em>, <strong>watch movie<\/strong> will not proceed to <strong>alert<\/strong>.<\/p>\n<p>A function with an empty return or without it returns <strong>undefined<\/strong>.<\/p>\n<p>If a function does not return a value, it is the same as if it returns <strong>undefined<\/strong>:<\/p>\n<p><code>function noHacerNada() { \/* vac\u00edo*\/ }<br \/>alert( noHacerNada() === undefined ); \/\/ true<\/code><\/p>\n<p>A\u00a0<strong>return<\/strong> empty is also the same as <strong>return undefined<\/strong>:<\/p>\n<pre data-enlighter-language=\"php\" class=\"EnlighterJSRAW\">function doNothing () {return; } alert (doNothing () === undefined); \/\/ true\n<\/pre>\n<p>Never add a new line between return and the value<br \/>For a long return expression, it might be tempting to put it on a separate line, like this:<\/p>\n<pre data-enlighter-language=\"php\" class=\"EnlighterJSRAW\">return (some + long + expression + or + whatever + is * f (a) + f (b))\n<\/pre>\n<p>That doesn&#039;t work, because JavaScript assumes a semicolon after <strong>return<\/strong>. That will work the same as:<\/p>\n<pre data-enlighter-language=\"php\" class=\"EnlighterJSRAW\">return; (some + long + expression + or + whatever + is * f (a) + f (b))\n<\/pre>\n<p>Therefore, it effectively becomes an empty return. We should put the value on the same line instead.<\/p>\n<\/p><\/div>","protected":false},"excerpt":{"rendered":"<p>Muy a menudo necesitamos realizar una acci\u00f3n similar en muchos lugares del script. Por ejemplo, debemos mostrar un mensaje atractivo cuando un visitante inicia sesi\u00f3n, cierra sesi\u00f3n y quiz\u00e1s en&#8230;<\/p>","protected":false},"author":1,"featured_media":95683,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1374],"tags":[],"class_list":["post-95682","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>Funciones en JavaScript - R Marketing Digital<\/title>\n<meta name=\"description\" content=\"Muy a menudo necesitamos realizar una acci\u00f3n similar en muchos lugares del script. Por ejemplo, debemos mostrar un mensaje atractivo cuando un visitante\" \/>\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\/funciones-en-javascript\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Funciones en JavaScript\" \/>\n<meta property=\"og:description\" content=\"Muy a menudo necesitamos realizar una acci\u00f3n similar en muchos lugares del script. Por ejemplo, debemos mostrar un mensaje atractivo cuando un visitante\" \/>\n<meta property=\"og:url\" content=\"https:\/\/rmarketingdigital.com\/en\/javascript\/funciones-en-javascript\/\" \/>\n<meta property=\"og:site_name\" content=\"R Marketing Digital\" \/>\n<meta property=\"article:published_time\" content=\"2022-09-10T18:05:16+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/rmarketingdigital.com\/wp-content\/uploads\/2020\/12\/Diseno-sin-titulo-13-2505417.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\\\/funciones-en-javascript\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/rmarketingdigital.com\\\/javascript\\\/funciones-en-javascript\\\/\"},\"author\":{\"name\":\"R Marketing Digital\",\"@id\":\"https:\\\/\\\/rmarketingdigital.com\\\/#\\\/schema\\\/person\\\/7c0d9782b2977b840b3740f00c69a73e\"},\"headline\":\"Funciones en JavaScript\",\"datePublished\":\"2022-09-10T18:05:16+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/rmarketingdigital.com\\\/javascript\\\/funciones-en-javascript\\\/\"},\"wordCount\":919,\"image\":{\"@id\":\"https:\\\/\\\/rmarketingdigital.com\\\/javascript\\\/funciones-en-javascript\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/rmarketingdigital.com\\\/wp-content\\\/uploads\\\/2020\\\/12\\\/Diseno-sin-titulo-13-2505417.png\",\"articleSection\":[\"Javascript\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/rmarketingdigital.com\\\/javascript\\\/funciones-en-javascript\\\/\",\"url\":\"https:\\\/\\\/rmarketingdigital.com\\\/javascript\\\/funciones-en-javascript\\\/\",\"name\":\"Funciones en JavaScript - R Marketing Digital\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/rmarketingdigital.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/rmarketingdigital.com\\\/javascript\\\/funciones-en-javascript\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/rmarketingdigital.com\\\/javascript\\\/funciones-en-javascript\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/rmarketingdigital.com\\\/wp-content\\\/uploads\\\/2020\\\/12\\\/Diseno-sin-titulo-13-2505417.png\",\"datePublished\":\"2022-09-10T18:05:16+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/rmarketingdigital.com\\\/#\\\/schema\\\/person\\\/7c0d9782b2977b840b3740f00c69a73e\"},\"description\":\"Muy a menudo necesitamos realizar una acci\u00f3n similar en muchos lugares del script. Por ejemplo, debemos mostrar un mensaje atractivo cuando un visitante\",\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/rmarketingdigital.com\\\/javascript\\\/funciones-en-javascript\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/rmarketingdigital.com\\\/javascript\\\/funciones-en-javascript\\\/#primaryimage\",\"url\":\"https:\\\/\\\/rmarketingdigital.com\\\/wp-content\\\/uploads\\\/2020\\\/12\\\/Diseno-sin-titulo-13-2505417.png\",\"contentUrl\":\"https:\\\/\\\/rmarketingdigital.com\\\/wp-content\\\/uploads\\\/2020\\\/12\\\/Diseno-sin-titulo-13-2505417.png\",\"width\":810,\"height\":450,\"caption\":\"diseno-sin-titulo-13-2505417-6233649-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":"Funciones en JavaScript - R Marketing Digital","description":"Very often we need to perform a similar action in many places in the script. For example, we must show an attractive message when a visitor","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\/funciones-en-javascript\/","og_locale":"en_US","og_type":"article","og_title":"Funciones en JavaScript","og_description":"Muy a menudo necesitamos realizar una acci\u00f3n similar en muchos lugares del script. Por ejemplo, debemos mostrar un mensaje atractivo cuando un visitante","og_url":"https:\/\/rmarketingdigital.com\/en\/javascript\/funciones-en-javascript\/","og_site_name":"R Marketing Digital","article_published_time":"2022-09-10T18:05:16+00:00","og_image":[{"width":810,"height":450,"url":"https:\/\/rmarketingdigital.com\/wp-content\/uploads\/2020\/12\/Diseno-sin-titulo-13-2505417.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\/funciones-en-javascript\/#article","isPartOf":{"@id":"https:\/\/rmarketingdigital.com\/javascript\/funciones-en-javascript\/"},"author":{"name":"R Marketing Digital","@id":"https:\/\/rmarketingdigital.com\/#\/schema\/person\/7c0d9782b2977b840b3740f00c69a73e"},"headline":"Funciones en JavaScript","datePublished":"2022-09-10T18:05:16+00:00","mainEntityOfPage":{"@id":"https:\/\/rmarketingdigital.com\/javascript\/funciones-en-javascript\/"},"wordCount":919,"image":{"@id":"https:\/\/rmarketingdigital.com\/javascript\/funciones-en-javascript\/#primaryimage"},"thumbnailUrl":"https:\/\/rmarketingdigital.com\/wp-content\/uploads\/2020\/12\/Diseno-sin-titulo-13-2505417.png","articleSection":["Javascript"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/rmarketingdigital.com\/javascript\/funciones-en-javascript\/","url":"https:\/\/rmarketingdigital.com\/javascript\/funciones-en-javascript\/","name":"Funciones en JavaScript - R Marketing Digital","isPartOf":{"@id":"https:\/\/rmarketingdigital.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/rmarketingdigital.com\/javascript\/funciones-en-javascript\/#primaryimage"},"image":{"@id":"https:\/\/rmarketingdigital.com\/javascript\/funciones-en-javascript\/#primaryimage"},"thumbnailUrl":"https:\/\/rmarketingdigital.com\/wp-content\/uploads\/2020\/12\/Diseno-sin-titulo-13-2505417.png","datePublished":"2022-09-10T18:05:16+00:00","author":{"@id":"https:\/\/rmarketingdigital.com\/#\/schema\/person\/7c0d9782b2977b840b3740f00c69a73e"},"description":"Very often we need to perform a similar action in many places in the script. For example, we must show an attractive message when a visitor","inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/rmarketingdigital.com\/javascript\/funciones-en-javascript\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/rmarketingdigital.com\/javascript\/funciones-en-javascript\/#primaryimage","url":"https:\/\/rmarketingdigital.com\/wp-content\/uploads\/2020\/12\/Diseno-sin-titulo-13-2505417.png","contentUrl":"https:\/\/rmarketingdigital.com\/wp-content\/uploads\/2020\/12\/Diseno-sin-titulo-13-2505417.png","width":810,"height":450,"caption":"diseno-sin-titulo-13-2505417-6233649-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\/95682","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=95682"}],"version-history":[{"count":0,"href":"https:\/\/rmarketingdigital.com\/en\/wp-json\/wp\/v2\/posts\/95682\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/rmarketingdigital.com\/en\/wp-json\/wp\/v2\/media\/95683"}],"wp:attachment":[{"href":"https:\/\/rmarketingdigital.com\/en\/wp-json\/wp\/v2\/media?parent=95682"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/rmarketingdigital.com\/en\/wp-json\/wp\/v2\/categories?post=95682"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/rmarketingdigital.com\/en\/wp-json\/wp\/v2\/tags?post=95682"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}