Here's the function:
const getUserIP = async () => {
let response = await fetch('https://jsonip.com/');
let json = await response.json();
console.log(json.ip)
return json.ip;
};
In the console, the IP address is logged as expected. However, when I save the 'IP address' to a variable:
const ip = getUserIP();
And then type ip
in the console, the value is shown as:
Promise { <state>: "fulfilled", <value>: "/* my IP here*/" }
I've watched videos on YouTube who have used the same logic/syntax albeit for a different API, but it works. I've searched Google and SO and couldn't find a thread with the same issue.
What am I missing?
Thanks.
async/await
works. Worth reading some doc/articles on them. – jfriend00