Working with Location

Location.current() shows [object Promise] when console.logged.

I’ve tried a for (key in location) loop to see what’s in the return, but I can’t figure it out. :thinking:

Give this a try… :wink:

console.log(await Location.current());

sylumer is right, using await should fix your problem.

Location.current() returns a promise. If you’re not used to promises, they can be a bit overwhelming but here’s a super short explanation.

What you get from calling Location.current() is an object that will either carry a value or an error, at some point in the future. Think of it as you are promised a value some time in the future but that value is not ready just yet. Unless of course the operation fails in which case you’ll get an error.

So how do we get the value that arrives some time in the future? Well, we wait. await Location.current() will tell the script to halt further execution and wait for the value, in this case the location, and then proceed whenever it has the value. However, if the operation fails the script will show an error instead.


Gotcha. a bit like firing of an ajax call in the middle of a function… Thank you, both.

1 Like