I try to understand behavior of try catch'ing async/ await function. Taking an example and invoking function:
(async () => {
try {
const res = await new Promise(res => {setTimeout(() => res({a: 1}), 2000)});
} catch(err) {
console.log('err: ', err);
}
console.log(res['a']);
})();
It results in error:
Uncaught (in promise) ReferenceError: res is not defined
at <anonymous>:7:14
How the code should be written if I do await assignment in a try block and I want make a further line use of the promise value?