title: Javascript: Change Global Variables but in a function without using "Promise"
body: <p>there my question is: How can I edit the variable "token" globally? I want to reuse the new value of that var, defined in that function. I know that it is not possible that easily, but are there ways to adapt that, so i can reuse the new value?</p>
  
  <p>I now know, that I can't really change that, but if I am reusing the "token" for example:</p>
  
  <pre><code>   console.log(token);
  </code></pre>
  
  <p>The return is "variable is undefined", but I am defining that at the top.</p>
  
  <p>My code is the following:</p>
  
  <pre><code>//libary:
  var Particle = require('particle-api-js');
  //neues Objekt:
  var particle = new Particle();
  //username, psw. etc definieren:
  var userName = 'email.adress';
  var passWord = 'passssword';
  //Scriptvariablen:
  var token;
  
  //Funktionen:
  function logontoparticle(){
          var test = particle.login({username: userName, password: passWord});
          test.then(
          function (data) {
                  token = data.body.access_token;
                  console.log('Logged In: with', token);
                  },
          function (err) {
                  console.log('LoggingIn Feeehlgeschalgen', err);
                  }
  );
  }
  
  logontoparticle();
  console.log("at end", token);
  </code></pre>
  
  <p>At the end I get the return: </p>
  
  <pre><code>"at end undefined"
  "token1234567891010201239" (e.g.)
  </code></pre>
  
  <p>I don't want to use: mockLogin and Promise... I want to avoid that... Thanks!</p>