G
G
Galdar Turin2019-10-09 09:01:14
Node.js
Galdar Turin, 2019-10-09 09:01:14

How to pull out a variable?

What are the options to move the data variable to the s variable?

var s;
                s = aut().then(function(data){
                    return data
                });
console.log(s);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Neverov, 2019-10-09
@Galdar

If ES6 is supported, use async/await: If not, then you are correct:

var s;
aut().then(data => {
  s = data;
});

But right after that, you can't console.log because the function is asynchronous. The variable s will be set when the aut() function is executed. It would be better to do:
var s;
aut().then(data => {
  s = data;
  console.log(s);
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question