title: ionic 2 local storage unable to set retrieved value to variable
body: <p>I am trying to set the value retrieved from .get function into a variable declared outside but unable to do so.</p>
  
  <pre><code>var dt;
  //retrieve
  this.local.get('didTutorial').then((value) =&gt; {
    alert(value);
     dt = value;
  })
  
  console.log("Local Storage value: "+dt);
  </code></pre>
  
  <p>I'm able to get "true" for the alert, but getting "undefined" for the console.log that is printing outside of the function.</p>
  
  <p><a href="https://i.stack.imgur.com/wh2v6.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/wh2v6.png" alt="enter image description here"></a>
  <a href="https://i.stack.imgur.com/mJ0ZP.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/mJ0ZP.png" alt="enter image description here"></a></p>
  
  <p>One workaround is that I can put all my remaining codes into the ".then function" , but that would be very messy. </p>
  
  <p><strong>Update(Solution):</strong></p>
  
  <p>As per ionic api (<a href="http://ionicframework.com/docs/v2/api/platform/storage/LocalStorage/" rel="nofollow noreferrer">http://ionicframework.com/docs/v2/api/platform/storage/LocalStorage/</a>) , they use .get to retrieve values. </p>
  
  <p>Since using promises has it's own limitations, by using the following:</p>
  
  <pre><code> constructor(navController) {
       this.navController = navController;
       this.local = new Storage(LocalStorage);
   }
  </code></pre>
  
  <p>and getItem function,</p>
  
  <pre><code>localStorage.getItem('didTutorial')
  </code></pre>
  
  <p>You will be able to retrieve it without having to put everything into the callback method.</p>