Ryan Crawford
Ryan Crawford

Reputation: 31

console.log works but return doesn't

I've been racking my brains with this one for some time. When I try to "return" the value of an AWS API to pass it to another function, it comes back undefined. When I console log that value, it works fine. In this case the returned value is an array and I am trying to grab the first element and not the full list.

function a() {
    inspector.listAssessmentTemplates(function(err, data) {
        let rntVal = data.assessmentTemplateArns[0]
        console.log(rntVal) **//outputs the expected string** 
        return rntVal
    })
}

function b() {
    let one = a()
    console.log(`${one}`) **//output is undefined**

b()

Upvotes: 0

Views: 35

Answers (0)

Related Questions