JavaScript How to use async and await correctly in nodejs?

When i run console.log (f ()) i want it returns the data that came from getData (url), but it keeps returning Promise {<pending>}. I thought using await keyword would solve this by making the code execution stops untilgetData ()returns something. I know if i use f().then(console.log) it will work fine, but i just don't understand why console.log (f()) does not works too. There is a way to achieve the same result f().then(console.log) but not using the then () function?

async function f() {
    const url = `https://stackoverflow.com`;
    let d = await getData(url);
    return d;
}

console.log(f());

If it is impossible, can you explain why?

Answer:1

f is an async function, so it still returns a Promise.

To wait for this promise to resolve you need to await it.

(async () => console.log(await f())();

Or in long:

async function run(){
   console.log(await f());
}
run();
Answer:2

Is it possible to mark (change color/size etc) vertex in editable Polygon? var polygon = new google.maps.Polygon({ map:_map, path:path, editable:true, ...

Is it possible to mark (change color/size etc) vertex in editable Polygon? var polygon = new google.maps.Polygon({ map:_map, path:path, editable:true, ...

  1. google maps polygon area
  2. google maps polygon tool
  3. google maps polygon label
  4. google maps polygon api
  5. google maps polygon edit event
  6. google maps polygon creator
  7. google maps polygon coordinates tool
  8. google maps polygon remove point
  9. google maps polygon z index
  10. google maps polygon fill pattern
  11. google maps polygon title
  12. google maps polygon click event
  13. google maps polygon center
  14. google maps polygon to geojson
  15. google maps polygon overlay
  16. google maps polygon infowindow
  17. google maps polygon drawing
  18. google maps polygon get coordinates
  19. google maps polygon get bounds
  20. google maps polygon with hole

I have this ejs file which is to be send as a response using res.render() in node.js <!DOCTYPE html> <html> <head> <title>pilcit</title> </head> <body> &...

I have this ejs file which is to be send as a response using res.render() in node.js <!DOCTYPE html> <html> <head> <title>pilcit</title> </head> <body> &...

just been reading this: https://reactjs.org/docs/react-api.html#reactpurecomponent and trying to work out when would a function not return something pure? surely if you give a component the same ...

just been reading this: https://reactjs.org/docs/react-api.html#reactpurecomponent and trying to work out when would a function not return something pure? surely if you give a component the same ...

  1. when would you use react

I need to redirect a page to another after 10seconds, and to do that, i'm using php header : header( "Refresh:10; url=http://myurl.local/test2.php", true, 303); But the problem is that when page ...

I need to redirect a page to another after 10seconds, and to do that, i'm using php header : header( "Refresh:10; url=http://myurl.local/test2.php", true, 303); But the problem is that when page ...

  1. force reload page chrome
  2. force reload page react
  3. force reload page javascript
  4. force reload page safari
  5. force reload page html
  6. force reload page on back button
  7. force reload page vue
  8. force reload page angular
  9. force reload page angular 5
  10. force reload page php
  11. force reload page jquery
  12. force reload page chrome mac
  13. force reload page firefox
  14. force reload page angular 6
  15. force reload page vuejs
  16. force reload page mac
  17. force reload page iphone
  18. force reload page c#
  19. force reload page from server
  20. force reload page asp.net