<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Mario Barceló]]></title><description><![CDATA[💻 Frontend Developer. 📱 Tech passionate. 🎲 Board Game lover. 🏈 Football rookie.]]></description><link>https://blog.mariobarcelo.dev</link><generator>RSS for Node</generator><lastBuildDate>Fri, 10 Apr 2026 14:00:46 GMT</lastBuildDate><atom:link href="https://blog.mariobarcelo.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Cómo hacer que Prettier no formatee código]]></title><description><![CDATA[Prettier nos ayuda entre otras cosas a que nuestro código quede visualmente ordenado y homogéneo.
No obstante hay ocasiones donde puede que queramos que Prettier no formatee nuestro código.
Por ejemplo, imaginemos que tenemos un código en formato JSO...]]></description><link>https://blog.mariobarcelo.dev/como-hacer-que-prettier-no-formatee-codigo</link><guid isPermaLink="true">https://blog.mariobarcelo.dev/como-hacer-que-prettier-no-formatee-codigo</guid><category><![CDATA[JavaScript]]></category><dc:creator><![CDATA[Mario Barceló]]></dc:creator><pubDate>Fri, 02 Jun 2023 06:23:05 GMT</pubDate><content:encoded><![CDATA[<p>Prettier nos ayuda entre otras cosas a que nuestro código quede visualmente ordenado y homogéneo.</p>
<p>No obstante hay ocasiones donde puede que queramos que Prettier no formatee nuestro código.</p>
<p>Por ejemplo, imaginemos que tenemos un código en formato JSON que queremos meter dentro de un array:</p>
<pre><code class="lang-json">[{
    <span class="hljs-attr">"id"</span>: <span class="hljs-string">"5d86371f1efebc31def272e2"</span>,
    <span class="hljs-attr">"about"</span>: <span class="hljs-string">"Ipsum duis incididunt ullamco tempor. Amet incididunt Lorem consequat labore culpa."</span>
  },
  {
    <span class="hljs-attr">"id"</span>: <span class="hljs-string">"5d86371f2343e37870b91ef1"</span>,
    <span class="hljs-attr">"about"</span>: <span class="hljs-string">"Mollit officia ad excepteur anim proident incididunt eiusmod mollit consectetur id sit velit. Laborum ut magna officia qui laboris eiusmod do culpa."</span>
  },
  {
    <span class="hljs-attr">"id"</span>: <span class="hljs-string">"5d86371f25a058e5b1c8a65e"</span>,
    <span class="hljs-attr">"about"</span>: <span class="hljs-string">"Laboris est duis eiusmod adipisicing cillum ut sit ea Lorem non laboris quis Lorem. Est culpa esse aliqua non labore dolor esse labore nulla mollit."</span>
  }]
</code></pre>
<p>Prettier nos lo transformaría de tal modo que quitaría las comillas de las llaves, porque interpreta que son objetos de JavaScript:</p>
<pre><code class="lang-javascript">[{
    <span class="hljs-attr">id</span>: <span class="hljs-string">"5d86371f1efebc31def272e2"</span>,
    <span class="hljs-attr">about</span>: <span class="hljs-string">"Ipsum duis incididunt ullamco tempor. Amet incididunt Lorem consequat labore culpa."</span>
  },
  {
    <span class="hljs-attr">id</span>: <span class="hljs-string">"5d86371f2343e37870b91ef1"</span>,
    <span class="hljs-attr">about</span>: <span class="hljs-string">"Mollit officia ad excepteur anim proident incididunt eiusmod mollit consectetur id sit velit. Laborum ut magna officia qui laboris eiusmod do culpa."</span>
  },
  {
    <span class="hljs-attr">id</span>: <span class="hljs-string">"5d86371f25a058e5b1c8a65e"</span>,
    <span class="hljs-attr">about</span>: <span class="hljs-string">"Laboris est duis eiusmod adipisicing cillum ut sit ea Lorem non laboris quis Lorem. Est culpa esse aliqua non labore dolor esse labore nulla mollit."</span>
  }]
</code></pre>
<p>Para decirle a Prettier que no queremos que formatee esté código simplemente tenemos que agregar el comentario "prettier-ignore" encima del bloque de código en cuestión:</p>
<pre><code class="lang-json"><span class="hljs-comment">// prettier-ignore</span>
[{
    <span class="hljs-attr">"id"</span>: <span class="hljs-string">"5d86371f1efebc31def272e2"</span>,
    <span class="hljs-attr">"about"</span>: <span class="hljs-string">"Ipsum duis incididunt ullamco tempor. Amet incididunt Lorem consequat labore culpa."</span>
  },
  {
    <span class="hljs-attr">"id"</span>: <span class="hljs-string">"5d86371f2343e37870b91ef1"</span>,
    <span class="hljs-attr">"about"</span>: <span class="hljs-string">"Mollit officia ad excepteur anim proident incididunt eiusmod mollit consectetur id sit velit. Laborum ut magna officia qui laboris eiusmod do culpa."</span>
  },
  {
    <span class="hljs-attr">"id"</span>: <span class="hljs-string">"5d86371f25a058e5b1c8a65e"</span>,
    <span class="hljs-attr">"about"</span>: <span class="hljs-string">"Laboris est duis eiusmod adipisicing cillum ut sit ea Lorem non laboris quis Lorem. Est culpa esse aliqua non labore dolor esse labore nulla mollit."</span>
  }]
</code></pre>
<p>Así le haremos saber a Prettier que no debe formatear el código siguiente.</p>
]]></content:encoded></item><item><title><![CDATA[Hello World con React]]></title><description><![CDATA[Vamos a aprender cómo mostrar un "Hello World" con React.
// 1. Importamos dependencias
import React from 'react';
import { createRoot } from 'react-dom/client';

// 2. Creamos un elemento de React
const element = React.createElement(
  'p',
  { id: ...]]></description><link>https://blog.mariobarcelo.dev/hello-world-con-react</link><guid isPermaLink="true">https://blog.mariobarcelo.dev/hello-world-con-react</guid><category><![CDATA[React]]></category><category><![CDATA[Web Development]]></category><category><![CDATA[webdev]]></category><category><![CDATA[Frontend Development]]></category><dc:creator><![CDATA[Mario Barceló]]></dc:creator><pubDate>Wed, 03 May 2023 09:17:41 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1683107267017/2e106c79-0992-4c48-a1f1-4c79f85e3cfc.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Vamos a aprender cómo mostrar un "Hello World" con React.</p>
<pre><code class="lang-javascript"><span class="hljs-comment">// 1. Importamos dependencias</span>
<span class="hljs-keyword">import</span> React <span class="hljs-keyword">from</span> <span class="hljs-string">'react'</span>;
<span class="hljs-keyword">import</span> { createRoot } <span class="hljs-keyword">from</span> <span class="hljs-string">'react-dom/client'</span>;

<span class="hljs-comment">// 2. Creamos un elemento de React</span>
<span class="hljs-keyword">const</span> element = React.createElement(
  <span class="hljs-string">'p'</span>,
  { <span class="hljs-attr">id</span>: <span class="hljs-string">'hello'</span> },
  <span class="hljs-string">'Hello World!'</span>
);

<span class="hljs-comment">// 3. Renderizamos la aplicación</span>
<span class="hljs-keyword">const</span> container = <span class="hljs-built_in">document</span>.querySelector(<span class="hljs-string">'#root'</span>);
<span class="hljs-keyword">const</span> root = createRoot(container);
root.render(element);
</code></pre>
<p>En primer lugar importamos las dependencias, que son tanto React mismo como el <em>renderer</em> react-dom.</p>
<p>En segundo lugar creamos el elemento de React, donde usamos la función React.createElement, la cual acepta estos 3 o más argumentos:</p>
<ol>
<li><p>El tipo de elemento a crear.</p>
</li>
<li><p>Las propiedades que queremos que tenga este elemento.</p>
</li>
<li><p>El contenido del elemento.</p>
</li>
</ol>
<p>Esta función nos devolverá un elemento de React, el cual es un objeto de JavaScript, y luce tal que así:</p>
<pre><code class="lang-javascript">{
  <span class="hljs-attr">type</span>: <span class="hljs-string">"p"</span>,
  <span class="hljs-attr">key</span>: <span class="hljs-literal">null</span>,
  <span class="hljs-attr">ref</span>: <span class="hljs-literal">null</span>,
  <span class="hljs-attr">props</span>: {
    <span class="hljs-attr">id</span>: <span class="hljs-string">'hello'</span>,
    <span class="hljs-attr">children</span>: <span class="hljs-string">'Hello World!'</span>,
  },
  <span class="hljs-attr">_owner</span>: <span class="hljs-literal">null</span>,
  <span class="hljs-attr">_store</span>: { <span class="hljs-attr">validated</span>: <span class="hljs-literal">false</span> }
}
</code></pre>
<p>En tercer lugar renderizamos la aplicación. Esto lo hacemos seleccionando el contenedor, luego creando el <em>root</em> en ese contenedor y por último renderizando en elemento en el <em>root</em>.</p>
<p>Inspirado en la explicación de Josh Comeau en su curso <a target="_blank" href="https://www.joyofreact.com/">The Joy of React</a>.</p>
]]></content:encoded></item><item><title><![CDATA[How to check if an array includes a value]]></title><description><![CDATA[To easily know if an array includes a value we can use the includes() method:
let items = [ "Computer", "Monitor" ];

items.includes("computer"); // false

items.includes("Computer"); // true

As you can see it is case sensitive. And you can check fo...]]></description><link>https://blog.mariobarcelo.dev/how-to-check-if-an-array-includes-a-value</link><guid isPermaLink="true">https://blog.mariobarcelo.dev/how-to-check-if-an-array-includes-a-value</guid><category><![CDATA[JavaScript]]></category><dc:creator><![CDATA[Mario Barceló]]></dc:creator><pubDate>Mon, 12 Dec 2022 10:58:42 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1683103938071/2888332a-8819-4bd1-8a6b-6be3c2c387d3.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>To easily know if an array includes a value we can use the <strong>includes()</strong> method:</p>
<pre><code class="lang-js"><span class="hljs-keyword">let</span> items = [ <span class="hljs-string">"Computer"</span>, <span class="hljs-string">"Monitor"</span> ];

items.includes(<span class="hljs-string">"computer"</span>); <span class="hljs-comment">// false</span>

items.includes(<span class="hljs-string">"Computer"</span>); <span class="hljs-comment">// true</span>
</code></pre>
<p>As you can see <strong>it is case sensitive</strong>. And you can check for example numbers too:</p>
<pre><code class="lang-js"><span class="hljs-keyword">let</span> numbers = [ <span class="hljs-number">4</span>, <span class="hljs-number">10</span>, <span class="hljs-number">27</span> ];

numbers.includes(<span class="hljs-number">2</span>); <span class="hljs-comment">// false</span>

numbers.includes(<span class="hljs-number">10</span>); <span class="hljs-comment">// true</span>
</code></pre>
<p><strong>It will return true if the value is found</strong> within the array <strong>or false if it's not</strong>.</p>
]]></content:encoded></item><item><title><![CDATA[Array destructuring in JavaScript]]></title><description><![CDATA[When we have an array and we want to extract the variables we can do it like this:
const fruits = ['apple', 'strawberry', 'banana', 'orange'];

const apple = fruits[0] // apple

const strawberry = fruits[1] // strawberry

const banana = fruits[2] // ...]]></description><link>https://blog.mariobarcelo.dev/array-destructuring-in-javascript</link><guid isPermaLink="true">https://blog.mariobarcelo.dev/array-destructuring-in-javascript</guid><category><![CDATA[JavaScript]]></category><category><![CDATA[Web Development]]></category><category><![CDATA[webdev]]></category><category><![CDATA[Frontend Development]]></category><dc:creator><![CDATA[Mario Barceló]]></dc:creator><pubDate>Thu, 08 Dec 2022 17:30:34 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1683104084217/a5103e7a-7ef7-43a7-b78f-79c87e8aa7d9.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>When we have an array and we want to extract the variables we can do it like this:</p>
<pre><code class="lang-plaintext">const fruits = ['apple', 'strawberry', 'banana', 'orange'];

const apple = fruits[0] // apple

const strawberry = fruits[1] // strawberry

const banana = fruits[2] // banana

const orange = fruits[3] // orange
</code></pre>
<p>But we can make it easier:</p>
<pre><code class="lang-plaintext">const fruits = ['apple', 'strawberry', 'banana', 'orange'];

const [ apple, strawberry, banana, orange ] = fruits
</code></pre>
<p>Now there is a variable called apple that has the 'apple' value assigned.</p>
<h2 id="heading-how-does-it-work">How does it work?</h2>
<p>This is called destructuring. We assign the first new variable to the first element of the array. And the same for the other variables and values.</p>
<p>Let's see it again but with different names, and we won't create the same number of variables as values of the array:</p>
<pre><code class="lang-plaintext">const fruits = ['apple', 'strawberry', 'banana', 'orange'];

const [ firstFruit, secondFruit ] = fruits
</code></pre>
<p>Now we have two new variables: firstFruit and secondFruit. firstFruit has the value of the first element of the fruits array, and secondFruit has the second element of the fruits array.</p>
<p>I like to think it like this: "I will create a variable called x from the array y"</p>
<pre><code class="lang-plaintext">const [newVariable1, newVariable2] = originalArray
</code></pre>
<p>But we won't always know the length of the array, so we can extract for example the first two positions of the array and then group the other on another array.</p>
<p>We'll use the rest operator (...)</p>
<pre><code class="lang-plaintext">const fruits = ['apple', 'strawberry', 'banana', 'orange'];

const [ firstElement, secondElement, ...otherElements ] = fruits
</code></pre>
<p>Can you think the value of each one of this new variables?</p>
<p>firstElement -&gt; 'apple'</p>
<p>secondElement -&gt; 'strawberry'</p>
<p>otherElements -&gt; [ 'banana', 'orange' ]</p>
<p>We have grouped the rest of the elements of the array to a new one array with the name we gave to the variable, in this example to otherElements.</p>
<p>The magic happens with the three dots before the name of the future new variable.</p>
<p>That's how you can destructure an array and go further with the rest operator!</p>
]]></content:encoded></item><item><title><![CDATA[Create an array and fill it at the same time in JavaScript]]></title><description><![CDATA[To create an array and fill it at the same time we'll create an Array instance and then we'll use the fill() method.
For example:
const myNumbers = Array(4).fill(0) // [ 0, 0, 0, 0 ]

We place as a parameter to fill() the value we want to place insid...]]></description><link>https://blog.mariobarcelo.dev/create-an-array-and-fill-it-at-the-same-time-in-javascript</link><guid isPermaLink="true">https://blog.mariobarcelo.dev/create-an-array-and-fill-it-at-the-same-time-in-javascript</guid><category><![CDATA[JavaScript]]></category><category><![CDATA[Web Development]]></category><category><![CDATA[webdev]]></category><category><![CDATA[Frontend Development]]></category><dc:creator><![CDATA[Mario Barceló]]></dc:creator><pubDate>Mon, 28 Nov 2022 18:35:00 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1683104064196/f4b8a99a-bfae-4ae0-bbc8-e0e033d98c37.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>To create an array and fill it at the same time we'll create an <strong>Array instance</strong> and then we'll use the <strong>fill() method</strong>.</p>
<p>For example:</p>
<pre><code class="lang-plaintext">const myNumbers = Array(4).fill(0) // [ 0, 0, 0, 0 ]
</code></pre>
<p>We place as a parameter to fill() the value we want to place inside the array.</p>
<h2 id="heading-extra-thing">Extra thing!</h2>
<p>Another thing we can use about the fill() method is <strong>substitute some values of the array with the value we want</strong>.</p>
<p>If we have this array:</p>
<pre><code class="lang-plaintext">let myNumbers = [ 1, 2, 3, 4 ]
</code></pre>
<p>We can use the fill() method to indicate:</p>
<ol>
<li><p>With which value to fill the array</p>
</li>
<li><p>Start of the filling</p>
</li>
<li><p>End of the filling</p>
</li>
</ol>
<p>We can fill the myNumbers array with the 0 number starting at the array position 2 and ending at the position 4, so the values 3 and 4 will be replaced by the zeros:</p>
<pre><code class="lang-plaintext">let myNumbers = [ 1, 2, 3, 4 ]

myNumbers.fill(0,2,4) // [ 1, 2, 0, 0 ]
</code></pre>
<p>The fill() method itself won't create new positions and values in the array, <strong>it will simply replace them</strong>.</p>
]]></content:encoded></item><item><title><![CDATA[What is the Spread operator in JavaScript?]]></title><description><![CDATA[The spread operator will copy the content of an iterable element like an array or a string. It will spread the content and won't mutate the original element. The syntax is three dots (...) and then the name of the element to copy.
Let's see an exampl...]]></description><link>https://blog.mariobarcelo.dev/what-is-the-spread-operator-in-javascript</link><guid isPermaLink="true">https://blog.mariobarcelo.dev/what-is-the-spread-operator-in-javascript</guid><category><![CDATA[JavaScript]]></category><category><![CDATA[Web Development]]></category><category><![CDATA[webdev]]></category><category><![CDATA[Frontend Development]]></category><dc:creator><![CDATA[Mario Barceló]]></dc:creator><pubDate>Mon, 28 Nov 2022 18:16:41 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1683104038525/739311fd-791f-484c-b769-22696a220817.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>The spread operator will <strong>copy the content</strong> of an iterable element like an array or a string. It will spread the content and <strong>won't mutate the original element</strong>. The syntax is three dots (...) and then the name of the element to copy.</p>
<p>Let's see an example:</p>
<pre><code class="lang-plaintext">const firstArray = [1,2,3]

const secondArray = [...firstArray, 4, 5]

firstArray // [ 1, 2, 3 ]
secondArray // [ 1, 2, 3, 4, 5 ]
</code></pre>
<p>The first element of the secondArray variable is the content of the firstArray variable. Each value will be placed on one index position and will be part of the array. Note that in the secondArray variable we also added other values to the array. This is possible in addition to the spread operator. Finally, when we see at the firstArray variable values haven't been modified.</p>
]]></content:encoded></item><item><title><![CDATA[How does the JavaScript slice() method work?]]></title><description><![CDATA[The slice() method** returns the selected items** of an array, but it won't mutate the original array. That's a difference with the splice() method.
slice() receives two parameters:

The starting index to remove

The end index (it won't be removed)

...]]></description><link>https://blog.mariobarcelo.dev/how-does-the-javascript-slice-method-work</link><guid isPermaLink="true">https://blog.mariobarcelo.dev/how-does-the-javascript-slice-method-work</guid><category><![CDATA[JavaScript]]></category><category><![CDATA[Web Development]]></category><category><![CDATA[webdev]]></category><category><![CDATA[Frontend Development]]></category><dc:creator><![CDATA[Mario Barceló]]></dc:creator><pubDate>Mon, 28 Nov 2022 18:15:04 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1683104008099/ab3e9221-fdaf-4671-b940-d1c525f00543.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>The slice() method** returns the selected items** of an array, but <strong>it won't mutate the original array</strong>. That's a difference with the <a target="_blank" href="https://blog.mariobarcelo.dev/how-does-the-javascript-splice-method-work">splice()</a> method.</p>
<p>slice() receives two parameters:</p>
<ol>
<li><p>The starting index to remove</p>
</li>
<li><p>The end index (it won't be removed)</p>
</li>
</ol>
<p>Let's see an example:</p>
<pre><code class="lang-plaintext">const numbers = [1,2,3,4,5]

const removedValues = numbers.slice(0,2)

removedValues // [ 1, 2 ]
numbers // [ 1, 2, 3, 4, 5 ]
</code></pre>
<p>We have the numbers array with five values. Then we use the slice() method to remove some. We set as a first parameter the starting index to remove as zero, because we want to start removing from the value 1 of the list. Then we set a 2 as a second parameter because we want to stop our removal at the index position 2. That means that position value won't be included, so the value 3 won't be part of the removed values.</p>
<p>Then slice() will return the removed values, in this case will return the 1 and 2 values. The interesting thing here is that the original array is not modified. Unlike <a target="_blank" href="https://blog.mariobarcelo.dev/how-does-the-javascript-splice-method-work">splice()</a>, slice() doesn't mutate the original array.</p>
]]></content:encoded></item><item><title><![CDATA[How does the JavaScript splice() method work?]]></title><description><![CDATA[The splice() method will remove items from an array. It will return the removed values and it will mutate the original array.
It receives two parameters:

The starting index to remove.
How many items will be removed from the starting position.

For e...]]></description><link>https://blog.mariobarcelo.dev/how-does-the-javascript-splice-method-work</link><guid isPermaLink="true">https://blog.mariobarcelo.dev/how-does-the-javascript-splice-method-work</guid><category><![CDATA[JavaScript]]></category><category><![CDATA[Web Development]]></category><category><![CDATA[Frontend Development]]></category><category><![CDATA[webdev]]></category><dc:creator><![CDATA[Mario Barceló]]></dc:creator><pubDate>Mon, 28 Nov 2022 16:42:28 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1683103975925/c956f967-fd3f-4216-9ee0-6f3ca7470fab.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>The splice() method will remove items from an array. It will <strong>return the removed values</strong> and it will <strong>mutate the original array</strong>.
It receives two parameters:</p>
<ol>
<li>The starting index to remove.</li>
<li>How many items will be removed from the starting position.</li>
</ol>
<p>For example:</p>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> numbers = [<span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-number">3</span>,<span class="hljs-number">4</span>,<span class="hljs-number">5</span>]

<span class="hljs-keyword">let</span> removedValues = numbers.splice(<span class="hljs-number">0</span>,<span class="hljs-number">2</span>)

removedValues <span class="hljs-comment">// [ 1, 2 ]</span>

numbers <span class="hljs-comment">// [ 3, 4, 5 ]</span>
</code></pre>
<p>In this example, we start on the position 0 of the array and we remove 2 items. In our example we delete the value of the index we are in and one more.</p>
<p>As we can see the splice() method returns the removed values and mutates the original array.</p>
]]></content:encoded></item></channel></rss>