Consider p and f (either variable or expression) where
p.then(f)
and f(await p)
are the same,
as shown in the examples below.
Ex 1: navigator.getBattery()
is a Promise,
display
is a function
navigator.getBattery().then(display)
display(await navigator.getBattery())
Ex 2: u
is a URL, fetch(u)
is a Promise,
call on the Response r.json()
is a Promise,
display
is a function
fetch(u).then(r => r.json()).then(display)
r=await fetch(u); display(await r.json())
First I wrote "exactly the same," but it turns out they are not.
It is strongly recommended
here
that await
should be prefered. See also
MDN docs and JS info