JavaScript Why I get pending from this function

async function test() {
    const res = await fetch('https://www.easy-mock.com/mock/5c6d317e8d040716434d0a5b/reading/category/homeSmallCategory');
    console.log(res) // data
    return res;
}
console.log(test()) // PromiseĀ {<pending>}

setTimeout(() => {
    console.log(test()) // PromiseĀ {<pending>}
})

Please parse it at the console.

How do I deal with this problem.I want the data processing in the test function .But it always return PromiseĀ {<pending>}. And then I think that I can deal with it like this.

if (res instanceof Promise) {
    res.then(data => res = data);
}

I put it at the end of the test.But it still not working.I console the Object.prototype.toString.call(res).And then I get [object Array].I realized that inside the function. The res is an array not matter what.But at the outside the res is not alike that. I know this is something about event loop.Thanks for your help.

Answer:1

I am using the Google Custom Search in my web page and want to filter the results before displaying the results. I cannot find any callback in Google's documenation where I can access the results so ...

I am using the Google Custom Search in my web page and want to filter the results before displaying the results. I cannot find any callback in Google's documenation where I can access the results so ...

  1. access google search history
  2. access google search console
  3. access google search data
  4. access google search api
  5. access google search box
  6. access my google search history
  7. can't access google search
  8. cannot access google search engine
  9. python access google search
  10. access vba google search
  11. access google voice search
  12. how to access google search settings
  13. how to access google search trends
  14. how to access google search
  15. cbs all access - google search
  16. how to access google search history on ipad
  17. how to access google search results
  18. google access music search history
  19. give access to google search console
  20. grant access to google search console

Is it possible to query firebase for documents in a collection where the number of elements in an array of a particular field is greater than 0 For my example, each document has-a field called '...

Is it possible to query firebase for documents in a collection where the number of elements in an array of a particular field is greater than 0 For my example, each document has-a field called '...

  1. firebase query documents

Introduction Hello, I'm trying to build a counter component for my online store, but I'm having trouble getting with it to function correctly. Problem From my understanding is that the count value ...

Introduction Hello, I'm trying to build a counter component for my online store, but I'm having trouble getting with it to function correctly. Problem From my understanding is that the count value ...

  1. react increment state property

For example: function Constructor() { this.peoperty = 1; this.myMethod1 = function() { //do something }; this.myMethod2 = function() { let a = myMethod3(); } /*no '...

For example: function Constructor() { this.peoperty = 1; this.myMethod1 = function() { //do something }; this.myMethod2 = function() { let a = myMethod3(); } /*no '...

  1. does vinegar kill viruses
  2. does hand sanitizer expire
  3. does he like me
  4. does target price match
  5. does the dog die
  6. does walmart price match
  7. does amazon price match
  8. does amazon pay taxes
  9. does water have memory
  10. does urine hold dna
  11. does wine go bad
  12. does medicare cover dental
  13. does noom work
  14. does zicam work
  15. does ups deliver on saturday
  16. does tamiflu work
  17. does usps deliver on sunday
  18. does polyester shrink
  19. does ups deliver on sunday
  20. does rogaine work