{"componentChunkName":"component---src-templates-blog-post-blog-post-js","path":"/es6-javascript/","result":{"data":{"site":{"siteMetadata":{"title":"girgetto.it"}},"markdownRemark":{"id":"e65a2fd1-5a4e-520c-81aa-1d1c693a4c8d","excerpt":"ES6 (ECMAScript 2015) fue la mayor actualización de JavaScript en su historia. Introdujo una sintaxis más moderna, patrones más limpios y herramientas que hoy…","html":"<p>ES6 (ECMAScript 2015) fue la mayor actualización de JavaScript en su historia. Introdujo una sintaxis más moderna, patrones más limpios y herramientas que hoy usamos a diario. En este artículo repasamos las features más importantes con ejemplos prácticos.</p>\n<hr>\n<h2 id=\"let-y-const--adiós-al-var\" style=\"position:relative;\"><a href=\"#let-y-const--adi%C3%B3s-al-var\" aria-label=\"let y const  adiós al var permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>let y const — Adiós al var</h2>\n<p>Antes de ES6, solo teníamos <code>var</code> para declarar variables. El problema era que <code>var</code> tiene <strong>scope de función</strong>, no de bloque, lo que causaba bugs inesperados.</p>\n<deckgo-highlight-code language=\"javascript\"  >\n          <code slot=\"code\">// ❌ var — scope de función, se puede redeclarar\nvar nombre = &quot;Ana&quot;;\nvar nombre = &quot;Luis&quot;; // No da error\n\n// ✅ let — scope de bloque, reasignable\nlet edad = 25;\nedad = 26; // OK\n\n// ✅ const — scope de bloque, no reasignable\nconst PI = 3.14159;\n// PI = 3; // ❌ TypeError: Assignment to constant variable</code>\n        </deckgo-highlight-code>\n<h3 id=\"diferencias-clave\" style=\"position:relative;\"><a href=\"#diferencias-clave\" aria-label=\"diferencias clave permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Diferencias clave</h3>\n<table>\n<thead>\n<tr>\n<th>Característica</th>\n<th><code>var</code></th>\n<th><code>let</code></th>\n<th><code>const</code></th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>Scope</td>\n<td>Función</td>\n<td>Bloque</td>\n<td>Bloque</td>\n</tr>\n<tr>\n<td>Redeclarable</td>\n<td>Sí</td>\n<td>No</td>\n<td>No</td>\n</tr>\n<tr>\n<td>Reasignable</td>\n<td>Sí</td>\n<td>Sí</td>\n<td>No</td>\n</tr>\n<tr>\n<td>Hoisting</td>\n<td>Sí (inicializado como <code>undefined</code>)</td>\n<td>Sí (temporal dead zone)</td>\n<td>Sí (temporal dead zone)</td>\n</tr>\n</tbody>\n</table>\n<blockquote>\n<p><strong>Regla general:</strong> Usa <code>const</code> por defecto. Usa <code>let</code> solo cuando necesites reasignar. Nunca uses <code>var</code>.</p>\n</blockquote>\n<hr>\n<h2 id=\"arrow-functions\" style=\"position:relative;\"><a href=\"#arrow-functions\" aria-label=\"arrow functions permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Arrow Functions</h2>\n<p>Las arrow functions son una forma más concisa de escribir funciones. Además, <strong>no crean su propio <code>this</code></strong>, lo que resuelve muchos problemas clásicos con callbacks.</p>\n<deckgo-highlight-code language=\"javascript\"  >\n          <code slot=\"code\">// Función tradicional\nfunction sumar(a, b) {\n  return a + b;\n}\n\n// Arrow function\nconst sumar = (a, b) =&gt; a + b;\n\n// Con un solo parámetro, los paréntesis son opcionales\nconst doble = x =&gt; x * 2;\n\n// Con cuerpo de múltiples líneas\nconst calcular = (a, b) =&gt; {\n  const resultado = a * b;\n  return resultado + 10;\n};</code>\n        </deckgo-highlight-code>\n<h3 id=\"el-problema-del-this-resuelto\" style=\"position:relative;\"><a href=\"#el-problema-del-this-resuelto\" aria-label=\"el problema del this resuelto permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>El problema del <code>this</code> resuelto</h3>\n<deckgo-highlight-code language=\"javascript\"  >\n          <code slot=\"code\">// ❌ Antes de ES6 — this se pierde en callbacks\nfunction Contador() {\n  this.count = 0;\n  setInterval(function () {\n    this.count++; // &#39;this&#39; NO es el Contador, es window/undefined\n  }, 1000);\n}\n\n// ✅ Con arrow function — this se hereda del scope padre\nfunction Contador() {\n  this.count = 0;\n  setInterval(() =&gt; {\n    this.count++; // &#39;this&#39; SÍ es el Contador\n  }, 1000);\n}</code>\n        </deckgo-highlight-code>\n<hr>\n<h2 id=\"template-literals\" style=\"position:relative;\"><a href=\"#template-literals\" aria-label=\"template literals permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Template Literals</h2>\n<p>Los template literals permiten crear strings con interpolación de variables y multilínea usando backticks.</p>\n<deckgo-highlight-code language=\"javascript\"  >\n          <code slot=\"code\">const nombre = &quot;Carlos&quot;;\nconst edad = 30;\n\n// ❌ Concatenación clásica\nconst saludo = &quot;Hola, me llamo &quot; + nombre + &quot; y tengo &quot; + edad + &quot; años.&quot;;\n\n// ✅ Template literal\nconst saludo = `Hola, me llamo ${nombre} y tengo ${edad} años.`;\n\n// Multilínea\nconst html = `\n  &lt;div class=&quot;card&quot;&gt;\n    &lt;h2&gt;${nombre}&lt;/h2&gt;\n    &lt;p&gt;Edad: ${edad}&lt;/p&gt;\n  &lt;/div&gt;\n`;\n\n// Expresiones dentro de ${}\nconst mensaje = `En 5 años tendré ${edad + 5} años.`;</code>\n        </deckgo-highlight-code>\n<hr>\n<h2 id=\"destructuring\" style=\"position:relative;\"><a href=\"#destructuring\" aria-label=\"destructuring permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Destructuring</h2>\n<p>El destructuring permite extraer valores de arrays y objetos en variables individuales de forma directa.</p>\n<h3 id=\"destructuring-de-objetos\" style=\"position:relative;\"><a href=\"#destructuring-de-objetos\" aria-label=\"destructuring de objetos permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Destructuring de objetos</h3>\n<deckgo-highlight-code language=\"javascript\"  >\n          <code slot=\"code\">const usuario = {\n  nombre: &quot;María&quot;,\n  edad: 28,\n  ciudad: &quot;Madrid&quot;,\n  trabajo: &quot;Desarrolladora&quot;\n};\n\n// ❌ Sin destructuring\nconst nombre = usuario.nombre;\nconst edad = usuario.edad;\n\n// ✅ Con destructuring\nconst { nombre, edad, ciudad } = usuario;\n\n// Renombrar variables\nconst { nombre: userName, edad: userAge } = usuario;\n\n// Valores por defecto\nconst { nombre, pais = &quot;España&quot; } = usuario;\n\n// Destructuring anidado\nconst empresa = {\n  datos: {\n    nombre: &quot;TechCorp&quot;,\n    direccion: { ciudad: &quot;Barcelona&quot;, cp: &quot;08001&quot; }\n  }\n};\n\nconst { datos: { direccion: { ciudad } } } = empresa;</code>\n        </deckgo-highlight-code>\n<h3 id=\"destructuring-de-arrays\" style=\"position:relative;\"><a href=\"#destructuring-de-arrays\" aria-label=\"destructuring de arrays permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Destructuring de arrays</h3>\n<deckgo-highlight-code language=\"javascript\"  >\n          <code slot=\"code\">const colores = [&quot;rojo&quot;, &quot;verde&quot;, &quot;azul&quot;, &quot;amarillo&quot;];\n\n// Extraer elementos\nconst [primero, segundo] = colores;\n// primero → &quot;rojo&quot;, segundo → &quot;verde&quot;\n\n// Saltar elementos\nconst [, , tercero] = colores;\n// tercero → &quot;azul&quot;\n\n// Rest operator\nconst [cabeza, ...resto] = colores;\n// cabeza → &quot;rojo&quot;, resto → [&quot;verde&quot;, &quot;azul&quot;, &quot;amarillo&quot;]\n\n// Intercambiar variables\nlet a = 1, b = 2;\n[a, b] = [b, a];\n// a → 2, b → 1</code>\n        </deckgo-highlight-code>\n<hr>\n<h2 id=\"spread-y-rest-operators-\" style=\"position:relative;\"><a href=\"#spread-y-rest-operators-\" aria-label=\"spread y rest operators  permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Spread y Rest Operators (...)</h2>\n<p>Los tres puntos (<code>...</code>) sirven para dos cosas: <strong>spread</strong> (expandir) y <strong>rest</strong> (recoger).</p>\n<deckgo-highlight-code language=\"javascript\"  >\n          <code slot=\"code\">// SPREAD — expandir arrays/objetos\n\nconst nums = [1, 2, 3];\nconst masNums = [...nums, 4, 5]; // [1, 2, 3, 4, 5]\n\n// Copiar un array (shallow copy)\nconst copia = [...nums];\n\n// Merge de objetos\nconst base = { color: &quot;azul&quot;, tamaño: &quot;M&quot; };\nconst extra = { tamaño: &quot;L&quot;, peso: &quot;200g&quot; };\nconst merged = { ...base, ...extra };\n// { color: &quot;azul&quot;, tamaño: &quot;L&quot;, peso: &quot;200g&quot; }\n\n// REST — recoger argumentos\nfunction sumarTodos(...numeros) {\n  return numeros.reduce((acc, n) =&gt; acc + n, 0);\n}\n\nsumarTodos(1, 2, 3, 4); // 10</code>\n        </deckgo-highlight-code>\n<hr>\n<h2 id=\"promesas-y-asyncawait\" style=\"position:relative;\"><a href=\"#promesas-y-asyncawait\" aria-label=\"promesas y asyncawait permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Promesas y Async/Await</h2>\n<p>Las promesas son el mecanismo estándar para manejar operaciones asíncronas en JavaScript.</p>\n<h3 id=\"promesas\" style=\"position:relative;\"><a href=\"#promesas\" aria-label=\"promesas permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Promesas</h3>\n<deckgo-highlight-code language=\"javascript\"  >\n          <code slot=\"code\">// Crear una promesa\nconst obtenerDatos = () =&gt; {\n  return new Promise((resolve, reject) =&gt; {\n    setTimeout(() =&gt; {\n      const datos = { id: 1, nombre: &quot;Producto&quot; };\n      resolve(datos);\n      // reject(new Error(&quot;Fallo al obtener datos&quot;));\n    }, 1000);\n  });\n};\n\n// Consumir la promesa\nobtenerDatos()\n  .then(datos =&gt; console.log(datos))\n  .catch(error =&gt; console.error(error))\n  .finally(() =&gt; console.log(&quot;Operación completada&quot;));</code>\n        </deckgo-highlight-code>\n<h3 id=\"asyncawait-es2017-pero-complementa-las-promesas-de-es6\" style=\"position:relative;\"><a href=\"#asyncawait-es2017-pero-complementa-las-promesas-de-es6\" aria-label=\"asyncawait es2017 pero complementa las promesas de es6 permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Async/Await (ES2017, pero complementa las promesas de ES6)</h3>\n<deckgo-highlight-code language=\"javascript\"  >\n          <code slot=\"code\">// Async/await hace que el código asíncrono parezca síncrono\nasync function cargarUsuario(id) {\n  try {\n    const response = await fetch(`/api/usuarios/${id}`);\n    const usuario = await response.json();\n    return usuario;\n  } catch (error) {\n    console.error(&quot;Error cargando usuario:&quot;, error);\n  }\n}\n\n// Ejecutar varias promesas en paralelo\nasync function cargarTodo() {\n  const [usuarios, productos] = await Promise.all([\n    fetch(&quot;/api/usuarios&quot;).then(r =&gt; r.json()),\n    fetch(&quot;/api/productos&quot;).then(r =&gt; r.json())\n  ]);\n\n  console.log(usuarios, productos);\n}</code>\n        </deckgo-highlight-code>\n<hr>\n<h2 id=\"módulos-import--export\" style=\"position:relative;\"><a href=\"#m%C3%B3dulos-import--export\" aria-label=\"módulos import  export permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Módulos (import / export)</h2>\n<p>ES6 introdujo un sistema de módulos nativo para JavaScript, permitiendo organizar el código en archivos separados.</p>\n<deckgo-highlight-code language=\"javascript\"  >\n          <code slot=\"code\">// 📁 utils/math.js\nexport const PI = 3.14159;\n\nexport function sumar(a, b) {\n  return a + b;\n}\n\nexport default function multiplicar(a, b) {\n  return a * b;\n}\n\n// 📁 app.js\nimport multiplicar, { PI, sumar } from &quot;./utils/math.js&quot;;\n\nconsole.log(sumar(2, 3));      // 5\nconsole.log(multiplicar(4, 5)); // 20\nconsole.log(PI);                // 3.14159</code>\n        </deckgo-highlight-code>\n<h3 id=\"tipos-de-exportimport\" style=\"position:relative;\"><a href=\"#tipos-de-exportimport\" aria-label=\"tipos de exportimport permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Tipos de export/import</h3>\n<deckgo-highlight-code language=\"javascript\"  >\n          <code slot=\"code\">// Named exports — puedes tener varios por archivo\nexport const nombre = &quot;valor&quot;;\nexport function fn() {}\n\n// Default export — solo uno por archivo\nexport default function principal() {}\n\n// Import con alias\nimport { sumar as add } from &quot;./math.js&quot;;\n\n// Import todo el módulo\nimport * as MathUtils from &quot;./math.js&quot;;\nMathUtils.sumar(1, 2);</code>\n        </deckgo-highlight-code>\n<hr>\n<h2 id=\"clases\" style=\"position:relative;\"><a href=\"#clases\" aria-label=\"clases permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Clases</h2>\n<p>ES6 introdujo la sintaxis <code>class</code> como azúcar sintáctico sobre el sistema de prototipos de JavaScript.</p>\n<deckgo-highlight-code language=\"javascript\"  >\n          <code slot=\"code\">class Animal {\n  constructor(nombre, sonido) {\n    this.nombre = nombre;\n    this.sonido = sonido;\n  }\n\n  hablar() {\n    return `${this.nombre} hace ${this.sonido}`;\n  }\n\n  // Getter\n  get info() {\n    return `${this.nombre} (${this.sonido})`;\n  }\n\n  // Método estático\n  static crearPerro() {\n    return new Animal(&quot;Perro&quot;, &quot;Guau&quot;);\n  }\n}\n\n// Herencia\nclass Gato extends Animal {\n  constructor(nombre, color) {\n    super(nombre, &quot;Miau&quot;);\n    this.color = color;\n  }\n\n  hablar() {\n    return `${super.hablar()} 🐱`;\n  }\n}\n\nconst michi = new Gato(&quot;Luna&quot;, &quot;negro&quot;);\nmichi.hablar(); // &quot;Luna hace Miau 🐱&quot;</code>\n        </deckgo-highlight-code>\n<hr>\n<h2 id=\"otras-features-importantes\" style=\"position:relative;\"><a href=\"#otras-features-importantes\" aria-label=\"otras features importantes permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Otras features importantes</h2>\n<h3 id=\"map-y-set\" style=\"position:relative;\"><a href=\"#map-y-set\" aria-label=\"map y set permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Map y Set</h3>\n<deckgo-highlight-code language=\"javascript\"  >\n          <code slot=\"code\">// Map — diccionario con claves de cualquier tipo\nconst mapa = new Map();\nmapa.set(&quot;nombre&quot;, &quot;Ana&quot;);\nmapa.set(42, &quot;la respuesta&quot;);\nmapa.set(true, &quot;booleano como clave&quot;);\n\nmapa.get(&quot;nombre&quot;); // &quot;Ana&quot;\nmapa.size;           // 3\n\n// Set — colección de valores únicos\nconst unicos = new Set([1, 2, 2, 3, 3, 3]);\n// Set {1, 2, 3}\n\nunicos.add(4);\nunicos.has(2);    // true\nunicos.delete(1);</code>\n        </deckgo-highlight-code>\n<h3 id=\"símbolos\" style=\"position:relative;\"><a href=\"#s%C3%ADmbolos\" aria-label=\"símbolos permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Símbolos</h3>\n<deckgo-highlight-code language=\"javascript\"  >\n          <code slot=\"code\">// Symbol — identificador único e inmutable\nconst id = Symbol(&quot;id&quot;);\nconst usuario = {\n  [id]: 123,\n  nombre: &quot;Pedro&quot;\n};\n\nusuario[id]; // 123\n// El símbolo no aparece en for...in ni Object.keys()</code>\n        </deckgo-highlight-code>\n<h3 id=\"valores-por-defecto-en-parámetros\" style=\"position:relative;\"><a href=\"#valores-por-defecto-en-par%C3%A1metros\" aria-label=\"valores por defecto en parámetros permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Valores por defecto en parámetros</h3>\n<deckgo-highlight-code language=\"javascript\"  >\n          <code slot=\"code\">function crearUsuario(nombre, rol = &quot;usuario&quot;, activo = true) {\n  return { nombre, rol, activo };\n}\n\ncrearUsuario(&quot;Ana&quot;);              // { nombre: &quot;Ana&quot;, rol: &quot;usuario&quot;, activo: true }\ncrearUsuario(&quot;Luis&quot;, &quot;admin&quot;);    // { nombre: &quot;Luis&quot;, rol: &quot;admin&quot;, activo: true }</code>\n        </deckgo-highlight-code>\n<h3 id=\"shorthand-en-objetos\" style=\"position:relative;\"><a href=\"#shorthand-en-objetos\" aria-label=\"shorthand en objetos permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Shorthand en objetos</h3>\n<deckgo-highlight-code language=\"javascript\"  >\n          <code slot=\"code\">const nombre = &quot;Sara&quot;;\nconst edad = 25;\n\n// ❌ Antes\nconst persona = { nombre: nombre, edad: edad };\n\n// ✅ ES6 shorthand\nconst persona = { nombre, edad };\n\n// Métodos shorthand\nconst calc = {\n  sumar(a, b) { return a + b; },\n  restar(a, b) { return a - b; }\n};</code>\n        </deckgo-highlight-code>\n<hr>\n<h2 id=\"conclusión\" style=\"position:relative;\"><a href=\"#conclusi%C3%B3n\" aria-label=\"conclusión permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Conclusión</h2>\n<p>ES6 transformó JavaScript de un lenguaje con muchas limitaciones a uno moderno y expresivo. Estas features no son solo azúcar sintáctico — cambian la forma en la que estructuramos, organizamos y pensamos nuestro código.</p>\n<p>Si aún no estás usando todas estas características, el mejor momento para empezar es ahora. La mayoría de navegadores modernos y Node.js las soportan nativamente, así que no hay excusas.</p>\n<p>¡Happy coding!</p>","wordCount":{"words":336},"frontmatter":{"title":"Guía esencial de ES6: Las features que transformaron JavaScript","date":"March 21, 2026","description":"Descubre las características más importantes de ECMAScript 2015 (ES6) que revolucionaron JavaScript: arrow functions, destructuring, template literals, promesas, módulos y mucho más.","lang":"es"},"tableOfContents":"<ul>\n<li>\n<p><a href=\"#let-y-const--adi%C3%B3s-al-var\">let y const — Adiós al var</a></p>\n<ul>\n<li><a href=\"#diferencias-clave\">Diferencias clave</a></li>\n</ul>\n</li>\n<li>\n<p><a href=\"#arrow-functions\">Arrow Functions</a></p>\n<ul>\n<li><a href=\"#el-problema-del-this-resuelto\">El problema del <code>this</code> resuelto</a></li>\n</ul>\n</li>\n<li>\n<p><a href=\"#template-literals\">Template Literals</a></p>\n</li>\n<li>\n<p><a href=\"#destructuring\">Destructuring</a></p>\n<ul>\n<li><a href=\"#destructuring-de-objetos\">Destructuring de objetos</a></li>\n<li><a href=\"#destructuring-de-arrays\">Destructuring de arrays</a></li>\n</ul>\n</li>\n<li>\n<p><a href=\"#spread-y-rest-operators-\">Spread y Rest Operators (...)</a></p>\n</li>\n<li>\n<p><a href=\"#promesas-y-asyncawait\">Promesas y Async/Await</a></p>\n<ul>\n<li><a href=\"#promesas\">Promesas</a></li>\n<li><a href=\"#asyncawait-es2017-pero-complementa-las-promesas-de-es6\">Async/Await (ES2017, pero complementa las promesas de ES6)</a></li>\n</ul>\n</li>\n<li>\n<p><a href=\"#m%C3%B3dulos-import--export\">Módulos (import / export)</a></p>\n<ul>\n<li><a href=\"#tipos-de-exportimport\">Tipos de export/import</a></li>\n</ul>\n</li>\n<li>\n<p><a href=\"#clases\">Clases</a></p>\n</li>\n<li>\n<p><a href=\"#otras-features-importantes\">Otras features importantes</a></p>\n<ul>\n<li><a href=\"#map-y-set\">Map y Set</a></li>\n<li><a href=\"#s%C3%ADmbolos\">Símbolos</a></li>\n<li><a href=\"#valores-por-defecto-en-par%C3%A1metros\">Valores por defecto en parámetros</a></li>\n<li><a href=\"#shorthand-en-objetos\">Shorthand en objetos</a></li>\n</ul>\n</li>\n<li>\n<p><a href=\"#conclusi%C3%B3n\">Conclusión</a></p>\n</li>\n</ul>"},"translations":{"nodes":[]},"previous":{"fields":{"slug":"/asincronia-javascript/"},"frontmatter":{"title":"Asincronía en JavaScript: Callbacks, Promesas y Async/Await"}},"next":{"fields":{"slug":"/git-comandos-basicos/"},"frontmatter":{"title":"Git desde cero: Guía práctica de los comandos básicos"}}},"pageContext":{"id":"e65a2fd1-5a4e-520c-81aa-1d1c693a4c8d","previousPostId":"cb704eab-d842-5103-b3d0-061e3a200651","nextPostId":"69173420-b876-5bb9-ac28-8b5aa9a4b0e4","baseSlug":"/es6-javascript/"}},"staticQueryHashes":["712016698"],"slicesMap":{}}