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?
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();
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, ...
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 ...
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 ...