I'm doing a little test with json I've turned into a variable using the JS fetch api, I've forgotten about scopes and I can't get the variable with the object outside of the function. I've tried return and other things but nothing has worked.
Code:
fetch(url)
.then(res => res.json())
.then((data) => {
let json = data;
})
.catch(err => { throw err });
console.log(json);
Error:
index.js:10 Uncaught ReferenceError: json is not defined
I haven't used JS in a long time, so help would be appreciated. Thanks.