title: JavaScript returns undefined - AWS Comprehend
body: <p>I'm trying to set up a function in which detects the language of the text sample (through AWS API) but I get in nodeJs I get undefined.</p>
  <pre class="lang-js prettyprint-override"><code>const fs = require('fs');
  var AWS = require('aws-sdk');
  AWS.config.update({ region: 'eu-west-1' });
  
  
  function languageDetection(test) {
  
      const params = { TextList: [test] };
      var comprehend = new AWS.Comprehend();
      comprehend.batchDetectDominantLanguage(params, function (err, data) {
          if (err) console.log(err, err.stack);
          else {
              const { ResultList } = data;
              const languages = ResultList[0][&quot;Languages&quot;];
              const detectedLanguage = languages[0]
              const detectedLanguageText = detectedLanguage[&quot;LanguageCode&quot;];
              return detectedLanguageText
          }
      });
  }
  
  let aTextExample = 'This is a sample text'
  const language = languageDetection(aTextExample)
  console.log(language)
  </code></pre>