title: How can I update the values of a global object inside of a function and then access its values with another function in JS?
body: <p>I'm trying to update the values of a global object inside of a function and then access it with another function in JS, with no success, my code is as follows:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var doguinho = {
      nome : "",
      idade : "",
      raca : "",
      coloracao : ""
  };
  
  $(document).ready(() =&gt; {
  
      $('button[name="btn-enviar"]').click(() =&gt; {
          doguinho.nome = $('input[id="input-nome"]').val();
          doguinho.idade = $('input[id="input-idade"]').val();
          doguinho.raca = $('input[id="input-raca"]').val();
          doguinho.coloracao = $('input[id="input-coloracao"]').val();
      })
  
      $('button[name="btn-mostrar"]').click(() =&gt; {
          alert(doguinho.nome);
      })
  }
  );</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;body&gt;
    &lt;script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"&gt;&lt;/script&gt;
    &lt;input type="text" id="input-nome"&gt;&lt;/input&gt;
    &lt;br/&gt;
    &lt;input type="text" id="input-idade"&gt;&lt;/input&gt;
    &lt;br/&gt;
    &lt;input type="text" id="input-raca"&gt;&lt;/input&gt;
    &lt;br/&gt;
    &lt;input type="text" id="input-coloracao"&gt;&lt;/input&gt;
    &lt;br/&gt;
    &lt;button type="submit" name="btn-enviar"&gt;save&lt;/button&gt;
    &lt;button type="submit" name="btn-mostrar"&gt;alert&lt;/button&gt;
  &lt;/body&gt;
  &lt;/html&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>As the object is declared in the global context shouldn't I be able to update ant then read its value from anywhere?</p>
  
  <p>If not, how can I do so?</p>