This probably has to do with asynchronous JavaScript and I'm having quite a bit of trouble figuring it out.
//inside another method
var ret = helper(tone_analyzer, myText);
console.log('loggerTwo');
function helper(tone_analyzer, myText) {
var b;
tone_analyzer.tone({text: myText}, function(err, result) {
console.log('loggerOne');
b = JSON.stringify(result, null, 2);
});
console.log(b)
return b;
}
Essentially, the output that I am getting is in ORDER 1) undefined 2) loggerTwo 3) loggerOne
Why is this happening?
EDIT: I have looked at the duplicate link and still cannot figure out where exactly this code would fit in
tone_analyzer.tone({text: myText}, function(err, result) {
console.log('loggerOne');
b = JSON.stringify(result, null, 2);
});
I've never used JavaScript before.