title: How to use DynamoDB DocumentClient().get() data outside of function
body: <p>I know this question has been asked before, but I haven't been able to find a clear answer.</p>
  <p>After retrieving data from my table in DynamoDB, I want to be able to store that data in a variable for use outside of the <code>docClient</code> function. I recognize that the way my code is set up, it tries to <code>console.log()</code> my <code>userData</code> variable before it finishes getting the data. I believe I need to use <code>async/await</code>, but I'm not sure how. I'm not very familiar with asynchronous JavaScript. Specific examples using this code would be very helpful. Thank you for looking at this for me!</p>
  <pre><code>var AWS = require('aws-sdk');
  AWS.config.update({region: 'us-west-2'});
  var docClient = new AWS.DynamoDB.DocumentClient({apiVersion: '2012-08-10'});
  
  var userData;
  
  var params = {
   TableName: 'someTableName',
   Key: {'UserID': '1'}
  };
  
  docClient.get(params, function(err, data) {
    if (err) {
      console.log(&quot;Error&quot;, err);
    } else {
      console.log(&quot;Success&quot;, data);
      userData = data.Item;
    }
  });
  
  console.log(userData); // Output: undefined
  </code></pre>