<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Karen Molina</title>
    <description>The latest articles on Forem by Karen Molina (@voidrizoma).</description>
    <link>https://forem.com/voidrizoma</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F648525%2F02599b5c-b4e5-40ea-a428-a81167dbddf9.jpeg</url>
      <title>Forem: Karen Molina</title>
      <link>https://forem.com/voidrizoma</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/voidrizoma"/>
    <language>en</language>
    <item>
      <title>Variables, tipos de dato, scope.</title>
      <dc:creator>Karen Molina</dc:creator>
      <pubDate>Wed, 07 Jun 2023 03:44:54 +0000</pubDate>
      <link>https://forem.com/voidrizoma/variables-tipos-de-dato-scope-c9</link>
      <guid>https://forem.com/voidrizoma/variables-tipos-de-dato-scope-c9</guid>
      <description>&lt;p&gt;Hace casi dos años &lt;a href="https://dev.to/voidrizoma/javascript-variables-tipos-de-dato-scope-y-el-hoisting-1fhb"&gt;escribía un post sobre el mismo tema&lt;/a&gt;, pero en estos meses, he descubierto que además de la importancia de escribir en español. Que siempre es un mar de información en el que te tienes que andar metiendo para entender cosas, sobre todo con JS, que es raro, pero así lo queremos &amp;lt;3. &lt;/p&gt;

&lt;h2&gt;
  
  
  Tipo de datos
&lt;/h2&gt;

&lt;p&gt;Los tipos de datos son importantes en cualquier lenguaje de programación. En el caso de JS, tenemos dos clases de datos: los primitivos y los de tipo objeto.&lt;/p&gt;

&lt;h3&gt;
  
  
  Datos primitivos
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Booleano (Boolean): Pueden representar dos valores lógicos: verdadero (true) y falso (false).&lt;/li&gt;
&lt;li&gt;Null: Representa un valor nulo. &lt;/li&gt;
&lt;li&gt;Undefined: Representa una variable que no ha sido asignada por un valor. &lt;/li&gt;
&lt;li&gt;Número (Number): Como su nombre lo indica, podemos representar cualquier número.&lt;/li&gt;
&lt;li&gt;BigInt: En JS tenemos dos tipos de números, el BigInt representa un valor exacto como los exponentes, algo así como: 2n ** 53n.&lt;/li&gt;
&lt;li&gt;Cadena de texto (String): Representa datos textuales, por ejemplo: "Hola olla".&lt;/li&gt;
&lt;li&gt;Symbol&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Datos tipo objeto
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Objetos&lt;/li&gt;
&lt;li&gt;Arreglos&lt;/li&gt;
&lt;li&gt;Funciones&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Los objetos y arreglos son los que conocemos de siempre.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Tuplas&lt;/li&gt;
&lt;li&gt;Records&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Éstos tipos de dato son nuevos y son muy similares al objeto y al array, pero cambia en unas cosas. Son inmutables, se trabaja con ellos por su valor y no por referencia... y tienen otras cosas medio chulas de las que iré escribiendo en otros posts.&lt;/p&gt;

&lt;h2&gt;
  
  
  Variables
&lt;/h2&gt;

&lt;p&gt;Se pueden definir de dos maneras: 1) una variable es un espacio almacenado en la memoria, 2) una variable es un contenedor para algún dato o valor. En JS tenemos tres formas de declarar estos valores: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;var&lt;/li&gt;
&lt;li&gt;let&lt;/li&gt;
&lt;li&gt;const&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  var
&lt;/h4&gt;

&lt;p&gt;Antes de EcmaScript 6 teníamos una manera de declarar nuestras variables y era con la palabra reservada "var". Pero eso nos daba un par de problemas; el primero era que podíamos&lt;br&gt;
duplicar las declaraciones y podríamos reasignar los valores. Suena a que no es un problema, pero si no teníamos el cuidado suficiente al trabajar nuestras variables, éstas podrían cambiar sin darnos cuenta. Ya que "var" nos permite la reasignación y la redeclaración.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;//var&lt;/span&gt;

&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;sayHello&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hola olla&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;sayHello&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// "Hola olla"&lt;/span&gt;

&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;sayHello&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hi!&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;sayHello&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// "Hi"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  let
&lt;/h4&gt;

&lt;p&gt;Con la llegada de ES6, el problema de reasignación de variables con var, termina. Especialmente cuando usamos la palabra reservada let dentro de las llaves { }. Así que además de darnos una keyword nueva, nos introduce a un nuevo scope; llamado: Block scope o alcance de bloque.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;//let &lt;/span&gt;

&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;sayHello&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hola olla&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;sayHello&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// "Hola olla"&lt;/span&gt;

&lt;span class="nx"&gt;sayHello&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hi!&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;sayHello&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// "Hi"&lt;/span&gt;

&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;sayHello&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hi!&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;sayHello&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// error: Identifier 'sayHello' has already been declared&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  const
&lt;/h4&gt;

&lt;p&gt;La palabra reservada "const" nos ayuda a guardar valores que nunca tendrán que reasignarse.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// const&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;sayHello&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hola olla&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;sayHello&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// "Hola olla"&lt;/span&gt;

&lt;span class="nx"&gt;sayHello&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hi!&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="c1"&gt;// error: Assignment to constant variable. &lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;sayHello&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hi!&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="c1"&gt;// error: Identifier 'sayHello' has already been declared&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;"const" es interesante, porque mientras lo relacionamos con variables constantes o que no cambian, en realidad no es tan así. De hecho se comporta diferente dependiendo el tipo de dato. En los datos primitivos tiene mucho sentido que con esta forma de declarar la variable, nos sea imposible reasignarla. Por lo que pareciera que "const" es de constante o para declarar variables inmutables, pero no es así. &lt;/p&gt;

&lt;p&gt;En los datos primitivos, las variables con "const" funcionan como de sólo lectura. Pero en los datos de tipo objeto, podemos cambiar propiedades del valor asignado a la variable. ¿khá?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;gato&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Simón&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;//Si queremos cambiar el nombre &lt;/span&gt;
&lt;span class="c1"&gt;//NO tenemos que hacer lo siguiente&lt;/span&gt;

&lt;span class="nx"&gt;gato&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Tito&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// De la forma anterior, no estamos cambiando &lt;/span&gt;
&lt;span class="c1"&gt;//una propiedad del valor asignado, estamos &lt;/span&gt;
&lt;span class="c1"&gt;//reasignando el valor de const. Entonces, &lt;/span&gt;
&lt;span class="c1"&gt;//para poder cambiar una propiedad, &lt;/span&gt;
&lt;span class="c1"&gt;//lo tenemos que hacer de la siguiente manera: &lt;/span&gt;

&lt;span class="nx"&gt;gato&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Tito&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;gato&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// "Tito"&lt;/span&gt;

&lt;span class="c1"&gt;// Ejemplo con arreglos&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;frutas&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Manzana&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Pera&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Fresa&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Melón&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;frutas&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt; &lt;span class="c1"&gt;// "Fresa"&lt;/span&gt;
&lt;span class="nx"&gt;frutas&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Uvas&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;frutas&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt; &lt;span class="c1"&gt;// "Uvas"&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Scope
&lt;/h2&gt;

&lt;p&gt;Ya llega la hora de hablar del scope. Entender el scope nos ayudará mucho a la hora  no solo de declarar nuestras variables, sino a entender muchas cosas a la hora de programar y pensar cómo solucionar nuestros problemas técnicos. El scope determina el alcance  de nuestras variables. Con JS tenemos tres tipos de scope: 1) global, 2) scope de función y 3) scope de bloque. Aunque en realidad podríamos agregar otros dos: local y de módulo.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Alcance global: Cuando declaramos variables fuera de cualquier función, automáticamente se convierte en una variable de alcance global.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Alcance de función: Cada vez que creamos funciones, se crea automáticamente un nuevo scope dentro de la nueva función. Eso significa que cada vez que declaramos variables dentro de una función, esa variable tendrá alcance o visibilidad dentro de esa función y no se podrá acceder a ella fuera de la función.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Alcance de bloque: el alcance de bloque llega a JS en 2015 con ES6, cuando se introducen let y const. Esto significa que cualquier variable declarada dentro de las llaves { } sólo pueden ser visibles dentro de ellas. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Alcance de Módulo: Cuando creamos un nuevo módulo, todas las variables que estén dentro del archivo aunque se encuentren fuera de funciones o llaves, en teoría podrían ser consideradas como variables globales; sin embargo, esas variables sólo tienen alcance a nivel de módulo, excepto cuando importamos explícitamente el módulo en otro archivo. &lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Extra || Valor o referencia en JS
&lt;/h2&gt;

&lt;p&gt;Cuando declaramos una variable, ésta se almacena en algún lugar de la memoria. Pero, funciona diferente para los datos primitivos y los de tipo objeto. Así que vamos por un ejemplo:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// 1&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// 1&lt;/span&gt;
&lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; 
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// 2&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// 1&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Acá pasa algo bien raro, bueno no raro, pero sí interesante. Cuando declaramos una variable y le asignamos un valor, éste queda almacenado en un lugar, pero cuando le asignamos la primera variable a otra variable, se crea una copia del valor y al mismo tiempo se vuelven independientes una de la otra; por lo tanto, por más que modifiquemos "a", el valor de "b" seguirá siendo 1.&lt;/p&gt;

&lt;p&gt;Pero en el caso de los objetos pasa algo curioso:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;fruta&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Fresa&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;red&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Ahí ya tenemos una variable que guarda un objeto. Que como ya sabemos, podemos modificar las propiedades de ese valor de fruta. Pero, a diferencia de los valores de los datos primitivos, en los objetos no se crean copias, lo que hace JS es apuntar al espacio de memoria donde guarda ese objeto y modifica sus propiedades. Entonces, si modificamos muchas veces las propiedades del objeto fruta, modificaremos los valores del objeto original, porque los cambios de hacen por referencia a ese espacio de memoria.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;fruta&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Fresa&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;red&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;fruta2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;fruta&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;fruta&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// { name: "Fresa", color: "red" }&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;fruta2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// { name: "Fresa", color: "red" }&lt;/span&gt;

&lt;span class="nx"&gt;fruta&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Manzana&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;fruta&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// { name: "Manzana", color: "red" }&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;fruta2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// { name: "Manzana", color: "red" }&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Así que cuando trabajemos con datos primitivos podemos estar seguros que manejamos valores, mientras que cuando usemos objetos, estaremos trabajando con referencias. Es por ello que es importante conocer conceptos como inmutabilidad o la importancia de la inclusión de Records y Tuplas como nuevos tipos de dato.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>beginners</category>
      <category>programming</category>
    </item>
    <item>
      <title>Hoisting: Some exercises.</title>
      <dc:creator>Karen Molina</dc:creator>
      <pubDate>Fri, 03 Dec 2021 00:28:16 +0000</pubDate>
      <link>https://forem.com/voidrizoma/hoisting-some-exercises-2efd</link>
      <guid>https://forem.com/voidrizoma/hoisting-some-exercises-2efd</guid>
      <description>&lt;p&gt;Hello! &lt;/p&gt;

&lt;p&gt;This time we will review the hoisting and the scope, one more time. Previously, we check them as concepts. But now, we going to realize come exercises to see how the hoisting and scope work inside the JS engine.&lt;/p&gt;

&lt;p&gt;Remember in JS we have three ways to make a declaration: var, let and const.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;variable&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// undefined&lt;/span&gt;
&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;variable&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hi&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;variable&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// Hi&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this case, if we call the variable with the keyword "var" before the initialization, JS returns an undefined value. That's happened because, with the hoisting, anything variable with a "var" keyword has been moved at the top. So, JS moves the initialization, but not the value or the assignation. The value has been assigned in line 2. &lt;/p&gt;

&lt;p&gt;What happens if we try to call our variables with the keywords "let" and "const" before the initialization?&lt;br&gt;
Let's see below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;variable2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;anotherVariable&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;variable2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hi, i'm a let&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;anotherVariable&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hi, i'm a const&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;

&lt;span class="c1"&gt;//ReferenceError: Cannot access anotherVariable' before initialization&lt;/span&gt;
&lt;span class="c1"&gt;//ReferenceError: Cannot access 'variable2' before initialization&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this case, we see that JS gives us an error, a specific error called: Reference Error, that's means that JS does not hoist the declarations with those keywords.&lt;/p&gt;

&lt;p&gt;Another issue with the hoisting happens in the functions. In this case, we must see some examples as to how the some of functions can be affected by the hoisting.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="c1"&gt;//5&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;num&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;num2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;num&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;num2&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;sum2&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="c1"&gt;//ReferenceError: Cannot access 'sum2' before initialization&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;sum2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;num1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;num2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;num1&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;num2&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;


&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;sumNumbers&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="c1"&gt;// ReferenceError: Cannot access 'sumNumbers' before initialization&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;sumNumbers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;num&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;num2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;num&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;num2&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this case and always all the functions as function declaration have moved at the top like the variable with "var", but with a small and important difference, in this case, the function work. Why?  The reason is that JS moves not just the initialization as a variable, JS moves the scope too. Meanwhile, a function expression and the arrow functions never will be moved at the top, and JS shows us a reference error if we invoke them before an initialization.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>beginners</category>
      <category>programming</category>
    </item>
    <item>
      <title>Asynchronous JavaScript: callbacks, promises and async/await.</title>
      <dc:creator>Karen Molina</dc:creator>
      <pubDate>Thu, 28 Oct 2021 02:40:45 +0000</pubDate>
      <link>https://forem.com/voidrizoma/asynchronous-javascript-callbacks-promises-and-asyncawait-22lm</link>
      <guid>https://forem.com/voidrizoma/asynchronous-javascript-callbacks-promises-and-asyncawait-22lm</guid>
      <description>&lt;p&gt;Hi! &lt;/p&gt;

&lt;p&gt;First JavaScript is a single-threaded programming language, which means only one thing can happen at a time. That happen, because the JavaScript engine can only process one statement at a time. So, the asynchronous is the action that do not happen at a time. And, Why is important understand the asynchronous in JS?. Always we work with data, sometimes we have to work with some APIs and depending the situation the server take some time to process the request at a time block the tread making the web unresponsive. That's where asynchronous comes into play. &lt;/p&gt;

&lt;p&gt;JavaScript has three ways to handle the asynchronous: callbacks, promises and async/await. &lt;/p&gt;

&lt;h3&gt;
  
  
  Callbacks
&lt;/h3&gt;

&lt;p&gt;A callback is a function passed into another functions as an argument.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;myName&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;hello&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;callback&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hello&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt; &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;callback&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;hello&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;myName&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Karen&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="c1"&gt;// Hello Karen&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this case, we have two functions, in the first, we need to get a value: name. So, we get it within a function. In the second function, we use the value that we returned at the first function and we use it in the second. So, to make it successful, we're going to passe the myName functions as a parameter inside the hello function. &lt;/p&gt;

&lt;h3&gt;
  
  
  Promises
&lt;/h3&gt;

&lt;p&gt;A promise is a special object in JavaScript, 'cause that links the producer code and consuming code. When we talk about producer code, we must through something that takes time to be processed. And the consuming code as something to provide us a result.&lt;/p&gt;

&lt;p&gt;A promise has two properties: the state and the result.&lt;br&gt;
The &lt;em&gt;state&lt;/em&gt; can be: pending, fulfilled and rejected.&lt;br&gt;
The &lt;em&gt;result&lt;/em&gt; can be: undefined, a result value or an error object.&lt;/p&gt;

&lt;p&gt;Now the syntax for a promise is next:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;thePromise&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Promise&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;reject&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;done&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nx"&gt;reject&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;…&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; 
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Inside a promise, we have two arguments: &lt;em&gt;resolve&lt;/em&gt; and &lt;em&gt;reject&lt;/em&gt;. Both arguments are callbacks provided by JS. The resolve callback is being executed if the job is finished successfully. Meanwhile, the reject is be executed if an error has occurred.&lt;/p&gt;

&lt;h3&gt;
  
  
  Async/Await
&lt;/h3&gt;

&lt;p&gt;Make the promises easier to write within two keywords:&lt;br&gt;
1.- Async: Makes a functions return a promise.&lt;br&gt;
2.- Await: Makes a functions wait for a promise.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;myName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;hello&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;myName&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Karen&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Hello &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; `&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// Hello Karen&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>javascript</category>
      <category>async</category>
      <category>codenewbie</category>
      <category>programming</category>
    </item>
    <item>
      <title>Coding Interview: Functions and closure.</title>
      <dc:creator>Karen Molina</dc:creator>
      <pubDate>Thu, 23 Sep 2021 04:53:02 +0000</pubDate>
      <link>https://forem.com/voidrizoma/coding-interview-functions-and-closure-6ck</link>
      <guid>https://forem.com/voidrizoma/coding-interview-functions-and-closure-6ck</guid>
      <description>&lt;p&gt;Hi! &lt;/p&gt;

&lt;p&gt;Now we going to review the functions and the closure.&lt;/p&gt;

&lt;h3&gt;
  
  
  Functions
&lt;/h3&gt;

&lt;p&gt;A function is similar to a procedure. A set or statements that performs a task. Also, a function in JS is a high-level object. &lt;/p&gt;

&lt;p&gt;We have many different ways to create functions.&lt;/p&gt;

&lt;p&gt;A function has a particular syntax.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--GoEmkHWr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1tc7905tm4c0m1n99i95.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--GoEmkHWr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1tc7905tm4c0m1n99i95.png" alt="A function has a particular syntax." width="800" height="765"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Function declaration
&lt;/h4&gt;

&lt;p&gt;A function declarations is the most easy mode to create a functions, just we must to use the keyword "function", followed by the name of the functions, the parameter inside parenthesis and the curly brackets with the statements.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;sum&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;num1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;num2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;num1&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;num2&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// =&amp;gt; 6&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Function expression
&lt;/h4&gt;

&lt;p&gt;For the beginners is easy to confuse the function declaration and functions expression. 'Cause both look very similar. &lt;/p&gt;

&lt;p&gt;But the functions expression does not start with "function" keyword. Here, the functions is created at the right side of the "assignment&lt;br&gt;
 expression" =:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;sum&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;num1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;num2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;num1&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;num2&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// =&amp;gt; 6&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  IIFE (Immediately Invoked Function Expression)
&lt;/h4&gt;

&lt;p&gt;An IIFE is a way to execute a function immediately after creation.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hello World&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// Hello World&lt;/span&gt;
&lt;span class="p"&gt;})()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Arrow Function
&lt;/h4&gt;

&lt;p&gt;In 2015 with ES6, the arrow functions was introduced. This way to create functions allow us to write with a shorter syntax.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;sum&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;num1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;num2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;num1&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;num2&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// =&amp;gt; 6&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Another feature introduce it was that return value by default. If the function has only one statement, the statement returns the value without the curly brackets&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;sum&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;num1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;num2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;num1&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;num2&lt;/span&gt;

&lt;span class="nx"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// =&amp;gt; 6&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Constructor
&lt;/h4&gt;

&lt;p&gt;In JS, a constructor is used to create objects. The purpose of a constructor is to create an object and set some of values. Is a simple way to create an object because we don't need to explicitly state what to return. By default, return the values which the constructor has been created.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;User&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;first&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;last&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;firstName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;first&lt;/span&gt;
  &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;lastName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;last&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;user1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;User&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Jon&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Snow&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;user1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;user2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;User&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Ned&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Stark&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;user2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Closure
&lt;/h3&gt;

&lt;p&gt;First, when we invoke a function, this create a new scope, with local variables. A closure is a function which has accessibility to variables and parameters from another function's scope.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;sayHi&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;hello&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hola&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
  &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;innerSayHi&lt;/span&gt;&lt;span class="p"&gt;(){&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;hello&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;innerSayHi&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;inner&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;sayHi&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

&lt;span class="nx"&gt;sayHi&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="c1"&gt;// "Hola"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>javascript</category>
      <category>programming</category>
    </item>
    <item>
      <title>JavaScript: Variables, tipos de dato, scope y el hoisting.</title>
      <dc:creator>Karen Molina</dc:creator>
      <pubDate>Sat, 18 Sep 2021 04:38:30 +0000</pubDate>
      <link>https://forem.com/voidrizoma/javascript-variables-tipos-de-dato-scope-y-el-hoisting-1fhb</link>
      <guid>https://forem.com/voidrizoma/javascript-variables-tipos-de-dato-scope-y-el-hoisting-1fhb</guid>
      <description>&lt;p&gt;¡Hola de nuevo! :3&lt;/p&gt;

&lt;p&gt;Algunas de las cosas básicas que tenemos que entender a la hora de querernos meter a aprender JavaScript son: variables, tipos de datos, scope y el Hoisting. En realidad, siempre estaremos o casi siempre estaremos en interacción con datos, ya sea que vengan del lado de nuestros servicios o datos con lo que tenemos que nos va a brindar el usuario. Así que como no podemos escapar de ellos, tenemos que aprender a manejarlos. &lt;/p&gt;

&lt;h3&gt;
  
  
  Tipo de datos
&lt;/h3&gt;

&lt;p&gt;Los tipos de datos son importantes en cualquier lenguaje de programación. En el caso de JS, tenemos dos clases de datos: los primitivos y los de tipo objeto. Dentro de los primitivos podemos encontrar diferentes tipos de datos: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Booleano (Boolean): Pueden representar dos valores lógicos: verdadero (true) y falso (false).&lt;/li&gt;
&lt;li&gt;Null: Representa un valor nulo. &lt;/li&gt;
&lt;li&gt;Undefined: Representa una variable que no ha sido asignada por un valor. &lt;/li&gt;
&lt;li&gt;Número (Number): Como su nombre lo indica, podemos representar cualquier número.&lt;/li&gt;
&lt;li&gt;BigInt: En JS tenemos dos tipos de números, el BigInt representa un valor exacto como los exponentes, algo así como: 2n ** 53n.&lt;/li&gt;
&lt;li&gt;Cadena de texto (String): Representa datos textuales, por ejemplo: "Hola olla".&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Variables
&lt;/h3&gt;

&lt;p&gt;Se pueden definir de dos maneras: 1) una variable es un espacio almacenado en la memoria, 2) una variable es un contenedor para algún dato o valor. En JS tenemos tres formas de declarar estos valores: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;var&lt;/li&gt;
&lt;li&gt;let&lt;/li&gt;
&lt;li&gt;const&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  var
&lt;/h4&gt;

&lt;p&gt;Antes de EcmaScript 6 teníamos una manera de declarar nuestras variables y era con la palabra reservada "var". Pero eso nos daba un par de problemas; el primero era que podíamos&lt;br&gt;
duplicar las declaraciones y podríamos reasignar los valores. Suena a que no es un problema, pero si no teníamos el cuidado suficiente al trabajar nuestras variables, éstas podrían cambiar sin darnos cuenta. Ya que "var" nos permite la reasignación y la redeclaración.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;//var&lt;/span&gt;

&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;sayHello&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hola olla&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;sayHello&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// "Hola olla"&lt;/span&gt;

&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;sayHello&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hi!&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;sayHello&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// "Hi"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  let
&lt;/h4&gt;

&lt;p&gt;Con la llegada de ES6, el problema de reasignación de variables con var, termina. Especialmente cuando usamos la palabra reservada let dentro de las llaves { }. Así que además de darnos una keyword nueva, nos introduce a un nuevo scope; llamado: Block scope o alcance de bloque.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;//let &lt;/span&gt;

&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;sayHello&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hola olla&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;sayHello&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// "Hola olla"&lt;/span&gt;

&lt;span class="nx"&gt;sayHello&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hi!&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;sayHello&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// "Hi"&lt;/span&gt;

&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;sayHello&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hi!&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;sayHello&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// error: Identifier 'sayHello' has already been declared&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  const
&lt;/h4&gt;

&lt;p&gt;La palabra reservada "const" nos ayuda a guardar valores que nunca tendrán que reasignarse.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// const&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;sayHello&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hola olla&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;sayHello&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// "Hola olla"&lt;/span&gt;

&lt;span class="nx"&gt;sayHello&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hi!&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="c1"&gt;// error: Assignment to constant variable. &lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;sayHello&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hi!&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="c1"&gt;// error: Identifier 'sayHello' has already been declared&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Scope
&lt;/h3&gt;

&lt;p&gt;Ya llega la hora de hablar del scope. Entender el scope nos ayudará mucho a la hora  no solo de declarar nuestras variables, sino a entender muchas cosas a la hora de programar y pensar cómo solucionar nuestros problemas técnicos. El scope determina el alcance  de nuestras variables. Con JS tenemos tres tipos de scope: 1) global, 2) scope de función y 3) scope de bloque. Aunque en realidad podríamos agregar otros dos: local y de módulo.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Alcance global: Cuando declaramos variables fuera de cualquier función, automáticamente se convierte en una variable de alcance global.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Alcance de función: Cada vez que creamos funciones, se crea automáticamente un nuevo scope dentro de la nueva función. Eso significa que cada vez que declaramos variables dentro de una función, esa variable tendrá alcance o visibilidad dentro de esa función y no se podrá acceder a ella fuera de la función.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Alcance de bloque: el alcance de bloque llega a JS en 2015 con ES6, cuando se introducen let y const. Esto significa que cualquier variable declarada dentro de las llaves { } sólo pueden ser visibles dentro de ellas. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Alcance de Módulo: Cuando creamos un nuevo módulo, todas las variables que estén dentro del archivo aunque se encuentren fuera de funciones o llaves, en teoría podrían ser consideradas como variables globales; sin embargo, esas variables sólo tienen alcance a nivel de módulo, excepto cuando importamos explícitamente el módulo en otro archivo. &lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Hoisting
&lt;/h3&gt;

&lt;p&gt;A veces JS hace cosas raras. Creo que el Hoisting es una de esas y si no lo entendemos podemos cometer algunos errores o bueno, tener algunos bugs algo raros. El Hoisting es un comportamiento que JS tiene por defecto y lo que hace es elevar todas las declaraciones. Cuando digo "elevar", me refiero a que coloca todas las declaraciones al inicio de su scope. Ese elevamiento no es literal, justo pasa cuando JS está en el proceso de compilación cuando JS hace un chequeo de todas las variables que requieren de algún espacio en la memoria. &lt;/p&gt;

&lt;p&gt;Gracias por leer y con gusto espero feedback :D&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>frontend</category>
      <category>programming</category>
    </item>
    <item>
      <title>HTML: Una cosa llamada !DOCTYPE</title>
      <dc:creator>Karen Molina</dc:creator>
      <pubDate>Sat, 18 Sep 2021 02:41:30 +0000</pubDate>
      <link>https://forem.com/voidrizoma/html-una-cosa-llamada-doctype-14g8</link>
      <guid>https://forem.com/voidrizoma/html-una-cosa-llamada-doctype-14g8</guid>
      <description>&lt;p&gt;¡Hola, ahora en español!&lt;/p&gt;

&lt;p&gt;Pues la idea de la serie de conceptos sobre cosas de frontend, es poder ayudarles a preparar sus entrevistas técnicas y por otro lado, me ayuda a repasar cosas que de pronto se olvidan. &lt;/p&gt;

&lt;p&gt;En HTML existe una cosa llamada !DOCTYPE. Primero, debemos de saber que no es una etiqueta del HTML. Ahora bien, aunque no es un tag, es una keyword o declaración importante dentro de nuestros archivos de HTML. &lt;/p&gt;

&lt;p&gt;Primero, pues cualquier cosa que hagamos, el navegador es el encargado de interpretar lo que estamos construyendo. En un inicio se supone que el !DOCTYPE se encagaba de avisar al navegador el tipo de documento que tendría que esperar, pero actualmente lo que informa es el versionado del HTML que estamos usando en el proyecto.  &lt;/p&gt;

&lt;p&gt;En el caso de HTML 5, la declaración es muy fácil, pues solo tenemos que poner:&lt;/p&gt;

&lt;p&gt;&amp;lt;!DOCTYPE html&amp;gt;&lt;/p&gt;

&lt;p&gt;La declaración anterior no indica explícitamente que sea un archivo de HTML 5, en realidad es una declaración por default, dado que antes del HTML5 se tenían que agregar algunos elementos de DTD que sí especificaran la versión del HTML que estábamos usando. &lt;/p&gt;

&lt;p&gt;Por ejemplo, para especificar un HTML 4, teníamos que colocar algo así: &lt;/p&gt;

&lt;p&gt;&amp;lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "&lt;a href="http://www.w3.org/TR/html4/loose.dtd%22%3E"&gt;http://www.w3.org/TR/html4/loose.dtd"&amp;gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Otra cosa a resaltar es que nuestro !DOCTYPE no es 'case sensitive', esto quiere decir que no importa si lo escribimos en mayúscula o minúscula; el navegador podrá interpretarlo. &lt;/p&gt;

</description>
      <category>html</category>
      <category>programming</category>
      <category>coding</category>
      <category>frontend</category>
    </item>
    <item>
      <title>Coding Interview: Variables, data types, scope and hoisting in JS</title>
      <dc:creator>Karen Molina</dc:creator>
      <pubDate>Thu, 16 Sep 2021 05:36:29 +0000</pubDate>
      <link>https://forem.com/voidrizoma/coding-interview-variables-data-types-scope-and-hoisting-in-js-2dgl</link>
      <guid>https://forem.com/voidrizoma/coding-interview-variables-data-types-scope-and-hoisting-in-js-2dgl</guid>
      <description>&lt;p&gt;Hi! &lt;/p&gt;

&lt;p&gt;Some of things we have to know about JS are: variables, data types, scope and hoisting. Why? 'Cause every time we use, transform and manipulate a lot of data. No matter if the data came from our services or the frontend. &lt;/p&gt;

&lt;h3&gt;
  
  
  Data Types
&lt;/h3&gt;

&lt;p&gt;The Data types are important in every programming languages. In JS we have two classes of types: primitives and objects. Primitives contains different data types:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Boolean: represent two logical values; true and false.&lt;/li&gt;
&lt;li&gt;Null: literal represent a null value. &lt;/li&gt;
&lt;li&gt;Undefined: A variable has not been assigned a value. &lt;/li&gt;
&lt;li&gt;Number: Any number&lt;/li&gt;
&lt;li&gt;BigInt: In JS we got two types of numbers, the BigInt means that we have to assign one exact value as: 2n ** 53n&lt;/li&gt;
&lt;li&gt;String: represent textual data. Example: "Hola olla"&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Variables
&lt;/h3&gt;

&lt;p&gt;A variable is a container for a data or value. In Javascript we have 3 ways to declare it: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;var&lt;/li&gt;
&lt;li&gt;let&lt;/li&gt;
&lt;li&gt;const&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  var
&lt;/h4&gt;

&lt;p&gt;Before EcmaScript 6, we use only the keyword var to storage our values. But with only one way to declare variables, we got a problem, all the var variables can be redeclared and updated.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;//var&lt;/span&gt;

&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;sayHello&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hola olla&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;sayHello&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// "Hola olla"&lt;/span&gt;

&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;sayHello&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hi!&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;sayHello&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// "Hi"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  let
&lt;/h4&gt;

&lt;p&gt;When ES6 arrived, the problem about updated the variables with var, has ended. Specially when we use variables inside curly brackets. So, ES6 introduce with let a new scope: the block scope.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;//let &lt;/span&gt;

&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;sayHello&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hola olla&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;sayHello&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// "Hola olla"&lt;/span&gt;

&lt;span class="nx"&gt;sayHello&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hi!&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;sayHello&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// "Hi"&lt;/span&gt;

&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;sayHello&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hi!&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;sayHello&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// error: Identifier 'sayHello' has already been declared&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  const
&lt;/h4&gt;

&lt;p&gt;Meanwhile let resolve the updated problem. Const resolve both problems. With const we can't updated or redeclared variables.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// const&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;sayHello&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hola olla&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;sayHello&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// "Hola olla"&lt;/span&gt;

&lt;span class="nx"&gt;sayHello&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hi!&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="c1"&gt;// error: Assignment to constant variable. &lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;sayHello&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hi!&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="c1"&gt;// error: Identifier 'sayHello' has already been declared&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Scope
&lt;/h3&gt;

&lt;p&gt;Ok, let's talks about scope. The scope determines the visibility or accessibility of variables. We have 3 types of scope: 1) Global scope, 2) Function scope, 3) block scope. But I want to add the local scope and the module scope.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Global scope: All the variables declared outside any function have global scope. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Function scope: When we create any new functions, each function creates a new scope. That's mean, all the variables declared inside the function, don't be accesible from any other functions outside. Other way to recognize the functions scope can be as local scope. All variables declared within a functions, are local variables.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Block scope&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The block scope has been introduced in ES6, with let and const. That's means, every variables declared inside the curly brackets { }, can't be accessed in other scope. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Module scope&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;When we create modules, any variables declared outside functions, can be considered as global variables, but no. Any variable declared inside the module just can be accessed inside that module, unless the module is explicitly exported.&lt;/p&gt;

&lt;h3&gt;
  
  
  Hoisting
&lt;/h3&gt;

&lt;p&gt;Sometimes JS is weird. And hoisting can be part of that strange things. The hoisting is a behavior in any variable or function can be used before declare it. That happened more before ES6, when we use the keyword var. &lt;/p&gt;

&lt;p&gt;After ES6, the hoisting is a default behavior of moving any declarations to the top of their scope. Remember, with let and const we have the block scope. So, any declaration is moved to the top. &lt;/p&gt;

&lt;p&gt;Also, one more thing to know is, JS hoists the declarations but cannot initialized. For example, if we have a var declaration, this will be initialized with an undefined value as default. &lt;/p&gt;

&lt;p&gt;I think hoisting is confused in the beginning, but, each time when JS has been compiled, all the declarations and functions are assigned in some memory space. So, the hoisting, move all declarations at top, to save that's declarations in the memory. Really, all the code stay how we wrote them.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>programming</category>
      <category>variables</category>
      <category>scope</category>
    </item>
    <item>
      <title>The coding interview: !DOCTYPE</title>
      <dc:creator>Karen Molina</dc:creator>
      <pubDate>Sun, 12 Sep 2021 03:37:32 +0000</pubDate>
      <link>https://forem.com/voidrizoma/the-coding-interview-doctype-4ilf</link>
      <guid>https://forem.com/voidrizoma/the-coding-interview-doctype-4ilf</guid>
      <description>&lt;p&gt;Hi, once again! &lt;/p&gt;

&lt;p&gt;Two years ago, I took my first job as frontend developer. Before that, I did workshops about STEAM for kids. And before at that I was studied Social Anthopology. So, a few months ago I applied to one of the big unicorns in LATAM, but I can't passed the proccess. My weakness: the theory.&lt;/p&gt;

&lt;p&gt;For that reason, I have been studying and reviewing about programming fundamentals. And thats why I have been decided create a serie of posts about technical interviews. To help other new and future programmers to get their dream jobs. Or to help them to give their best in a future interview.&lt;/p&gt;

&lt;p&gt;First we started with some of HTML. Why?, because, as a web developers the HTML is one of our three most important tools to create our projects. &lt;/p&gt;

&lt;p&gt;What is the !DOCTYPE?&lt;/p&gt;

&lt;p&gt;In every html file we must put !DOCTYPE in the first line, but, why?. First the !Doctype is not a html tag, but it's a keyword. This keyword works as a declaration to the browser. I mean, with that we says to the browser what document type must to expect. In that case, an HTML 5 file.&lt;/p&gt;

&lt;p&gt;The complete declaration must be like: &lt;/p&gt;

&lt;p&gt;&amp;lt;!DOCTYPE html&amp;gt;. &lt;/p&gt;

&lt;p&gt;Before HTML5, the declaration was more confused, because we had used some thing called Document Type Definition. But, don't worry, now, we dont have to use that. But other thing we have to know and help us in the future is about the case sensitive. The !DOCTYPE is not case sensitive. So, we can write with capitalize, uppercase, lowercase, camelcase ways. Not matters!. &lt;/p&gt;

</description>
      <category>javascript</category>
      <category>html</category>
      <category>css</category>
      <category>programming</category>
    </item>
    <item>
      <title>Guess the Number</title>
      <dc:creator>Karen Molina</dc:creator>
      <pubDate>Wed, 16 Jun 2021 02:52:00 +0000</pubDate>
      <link>https://forem.com/voidrizoma/guess-the-number-2jnc</link>
      <guid>https://forem.com/voidrizoma/guess-the-number-2jnc</guid>
      <description>&lt;p&gt;Hi! &lt;/p&gt;

&lt;p&gt;It's me! &lt;/p&gt;

&lt;p&gt;Remember my first post, &lt;a href="https://dev.to/voidrizoma/guess-the-number-19j3"&gt;Guess the Number with Python&lt;/a&gt;? Well, I decided to do the same exercise, now with Javascript.&lt;/p&gt;

&lt;p&gt;Let's go.... hands on code!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const prompt = require("prompt-sync")({ sigint: true });
let guessesTaken = 0;

console.log("Hola crayola.... ¿Cómo te llamas?");
const name = prompt();

let number = Math.floor(Math.random() * 10) + 1;
console.log(`Hola ${name}.... Adivina el número en el que estoy pensando`);

while (guessesTaken &amp;lt; 6) {
  console.log("Dime un número");
  guess = prompt();
  guessesTaken = guessesTaken + 1;
  if( guess &amp;lt; number){
      console.log("Es un número más alto")
  } else if (guess &amp;gt; number) {
      console.log("Es un número menor")
  }else if (guess == number) {
    console.log(`Felicidades ${name}. ${number} es el número!!`);
    break;
  } else {
    console.log(`uy no ${name}, estaba pensando en ${number}`);
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;At a first instance, we need to install prompt-sync node module to use it. Once time we have benn instaled the module, we can continue to code.&lt;/p&gt;

&lt;p&gt;We have three variables, one of them we use to create a record or a counter as how many times we try to guess the number. The second variable are use to save the user name. &lt;br&gt;
Then, we have a third variable, called number that we use the method math to get a randomly number between 1 to 10. And we have two console.log to create an interaction with the user, get the name and a number.&lt;/p&gt;

&lt;p&gt;Next, we create a while loop. A while its a loop that execute the core over and over again. We create a loop that the conditional must be menor that 6. In that case, 6 is the number that the user got to try to guess.&lt;/p&gt;

&lt;p&gt;Inside a while loop, we have a console.log and a varibale called guess. Then we have trhee conditional sentences. The first compare if the guess is menor that number. And the second if, gonna make a comparison if guess is mayor that number. Then we have anocher conditional that compare the guess and number varibales when the user knows the right number. In this block to code, we must return a succeful message as string, and we can brake the loop.&lt;/p&gt;

&lt;p&gt;Finally, the four conditional statement will be retured an error message when the user fails the game.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>beginners</category>
      <category>gamedev</category>
      <category>programming</category>
    </item>
    <item>
      <title>Dragon game</title>
      <dc:creator>Karen Molina</dc:creator>
      <pubDate>Tue, 15 Jun 2021 00:17:31 +0000</pubDate>
      <link>https://forem.com/voidrizoma/dragon-game-19e7</link>
      <guid>https://forem.com/voidrizoma/dragon-game-19e7</guid>
      <description>&lt;p&gt;Hello!&lt;br&gt;
Ok, let's start! Now, we can create a new game, you know the same book.&lt;br&gt;
I'm gonna put the code first, then I gotta explain it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import random
import time

def displayIntro():
    print("You are in a land full of dragons, In front of you,")
    print("you see two caves. In one cave, the dragons id friendly")
    print("and will share his treasure with you. The other dragon")
    print("is greedy and hungry, and will eat you in sight")

def chooseCave():
    cave = ""
    while cave != "1" and cave != "2":
        print("Which cave will you go into? (1 or 2)")
        cave = input()

    return cave

def checkCave(chooseCave):
    print("You approach the cave...")
    time.sleep(2)
    print("It is dark and spooky...")
    time.sleep(2)
    print("A large dragon jumps out in front of you! HE open his jaws...")
    print()
    time.sleep(2)

    friendlyCave = random.randint(1,2)

    if chooseCave == str(friendlyCave):
        print("Gives you his treasure!")
    else:
        print("Gobbles you down in one bite!")

playAgain = "yes"

while playAgain == "yes" or playAgain == "y":
    displayIntro()
    caveNumber = chooseCave()
    checkCave(caveNumber)
    print("Do you want to play again? (yes or no)")
    playAgain = input()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this program we use two modules: random and time module. &lt;/p&gt;

&lt;p&gt;Currently we use functions, the function is a way to say what to do and how. In python the functions has been writing with the statement defines or def. So, we have the firts block to code inside a function called displayIntro.&lt;br&gt;
Inside displayIntro function, we write a few print methods to introduce the user inside the game.&lt;/p&gt;

&lt;p&gt;Then we have the chooseCave function. Inside it, we put a empty varibale. Below we can write a while loop. Inside it, we have to compar two options or values: 1 and 2. Those values, are going to be the user options.&lt;/p&gt;

&lt;p&gt;The next function we have is called checkCave. In this function we have to write a twice print methods to start the story. Then, we have to question to user which are the way to choose. Immediately we have to do the comparison between his choose and a random number. This is why we use random module. To choose randomdly two options: number 1 or 2. The options that we return to user, depends that return the random module.&lt;/p&gt;

&lt;p&gt;Finnaly, we have to do another function to know if the user want to continue or left the game.  &lt;/p&gt;

</description>
      <category>python</category>
      <category>programming</category>
      <category>beginners</category>
      <category>gamedev</category>
    </item>
    <item>
      <title>Guess the Number</title>
      <dc:creator>Karen Molina</dc:creator>
      <pubDate>Sun, 13 Jun 2021 03:25:23 +0000</pubDate>
      <link>https://forem.com/voidrizoma/guess-the-number-19j3</link>
      <guid>https://forem.com/voidrizoma/guess-the-number-19j3</guid>
      <description>&lt;p&gt;Hi! &lt;/p&gt;

&lt;p&gt;Some months ago, I was thinking to practice my skills in python, but I don't want do stuff in backend. I had no idea how to start. So, one day, one friend at Twitter sais me: Hey! you can practice with that book!. The book called: Invent Your Own Games with Python by Al Sweigart.&lt;/p&gt;

&lt;p&gt;The first game I would to recreate is called: Guess the Number. We have to use the input, conditionals, booleans, Modules, statements to iterate some things... and other stuffs. The objective is...&lt;/p&gt;

&lt;p&gt;As a user. I have to write my name in the game to make a custom gretting at the beginning of the game. The game must return the greeting and said my name and give me the next instruction to continue the game.&lt;/p&gt;

&lt;p&gt;Let's go.... hands on code! &lt;/p&gt;






&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import random 

guessesTaken = 0

print("Hola crayola.... ¿Cómo te llamas?")
myName = input()

number = random.randint(1,20)
print("Hola" + myName + "Adivina el número en el que estoy pensando")

while guessesTaken &amp;lt; 6:
    print("date con un número")
    guess = input()
    guess = int(guess)

    guessesTaken = guessesTaken + 1

    if guess &amp;lt; number:
        print("ay no!..... es un número más alto")

    if guess &amp;gt; number:
        print("estás muy muy arriba, ve más abajo")

    if guess == number:
        break

if guess == number:
    guessesTaken = str(guessesTaken)
    print("Esoooo" + myName + "es el bueno")

if guess != number:
    number = str(number)
    print("nope! ese no es. Estuve pensando en" + number)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;First, we have to import the random Module. We need it to create a random variables... or numbers, in this case.&lt;/p&gt;

&lt;p&gt;Next, we create a variable named guessesTaken, this variable we use to create a record or a counter as how many times we try to guess the number. At lines 6-7 we create the first interaction with the user, we ask the name.&lt;/p&gt;

&lt;p&gt;At lines 9-10 we can use the random Module with the randint method. Inside the parentheses we can put two parameters, separated by commas. then randit(), return a random number between the parameters. The number been returned it be the number that the user going to try to guess.&lt;/p&gt;

&lt;p&gt;In line 12 we has to create a loop... we must use a while. A while its a loop that execute the core over and over again. We create a loop that the conditional must be menor that 6. In that case, 6 is the number that the user got to try to guess.&lt;/p&gt;

&lt;p&gt;Now, inside de While... we have few block to code. First, we ask to the user a number. Then we create two variables. One of then we use it for the number that the user write. The second varibale, we transform that value in a integrer. At line 17, we start the timer or the tryes that the user have. Remember... we created a loop with a six intents.&lt;/p&gt;

&lt;p&gt;Then we have two if statements. Both are gonna make a comparison between the guess variable and the number to guess. But, the first if, gonna make a comparison if the guess is menor that number. And the second if, gonna make a comparison if guess is mayor that number. &lt;/p&gt;

&lt;p&gt;Now, we have a third if statement inside while loop. That if indicate to the game that if guess is equal to number. The user has guessed the right number. At this moment.. the loop will be stoped.&lt;/p&gt;

&lt;p&gt;Once outside the loop we have two more if statements. &lt;/p&gt;

&lt;p&gt;Firts, a conditional that compare the guess and number varibales when the user knows the right number. In this block to code, we must return a succeful message as string, that why first we convert the guess varibale to string.&lt;/p&gt;

&lt;p&gt;Finally, the second if statement will be retured an error message when the user fails the game.&lt;/p&gt;

</description>
      <category>python</category>
      <category>gamedev</category>
      <category>beginners</category>
      <category>programming</category>
    </item>
  </channel>
</rss>
