-1

I'm trying to assign a value to variable from a callback, but in console.log it shows me undefined.

What am I doing wrong?

var threadsList = threads(data => {
  return data
})

console.log(threadsList)
mhatch
  • 4,441
  • 6
  • 36
  • 62
  • Possible duplicate of [How does Asynchronous Javascript Execution happen? and when not to use return statement?](https://stackoverflow.com/questions/7104474/how-does-asynchronous-javascript-execution-happen-and-when-not-to-use-return-st) – Emile Bergeron Jun 16 '17 at 02:31
  • it might no data is returned! – OmG Jun 16 '17 at 02:31
  • It would help to see the definition of `threads()` – mhatch Jun 16 '17 at 19:50
  • Your arrow function is returning data to `threads()` If `threads()` is not returning that data back, it will not be going into `threadsList` As an illustration try `var threadsList = threads(data => { console.log(data); })` This should log your data showing you that the callback was called. – mhatch Jun 16 '17 at 19:57

1 Answers1

0

Solved!

threads(data => {
  this.$data.threads = data
})
Gerard
  • 15,418
  • 5
  • 30
  • 52