title: How to declare the variables only once to be able to use in all functions "onclick"
body: <p>I would like to know how do I use the variables only once before the functions so I can use the variables without having to declare them again in each function?    </p>
  
  <pre><code>window.onload = function() {
      document.getElementById("soma").onclick = soma;
      document.getElementById("subtracao").onclick = subtracao;
      document.getElementById("multiplicacao").onclick = multiplicacao;
      document.getElementById("divicao").onclick = divicao;
  
      function soma() {
          var n1 = parseFloat(document.getElementById("n1").value);
          var n2 = parseFloat(document.getElementById("n2").value);
          document.getElementById("resultado").value = (n1 + n2);
      }
  
      function subtracao() {
          var n1 = parseFloat(document.getElementById("n1").value);
          var n2 = parseFloat(document.getElementById("n2").value);
          document.getElementById("resultado").value = (n1 - n2);
      }
  
      function multiplicacao() {
          var n1 = parseFloat(document.getElementById("n1").value);
          var n2 = parseFloat(document.getElementById("n2").value);
          document.getElementById("resultado").value = (n1 * n2);
      }
  
      function divicao() {
          var n1 = parseFloat(document.getElementById("n1").value);
          var n2 = parseFloat(document.getElementById("n2").value);
          document.getElementById("resultado").value = (n1 / n2);
      }
  }
  </code></pre>