我正在尝试在函数内设置全局变量,但是代码在变量已更新之前仍在继续。 例如
var username = 'Example';
const fetch = require('node-fetch');
var num = 1234;
var uuidP;
const request = async () => {
const response = await fetch(`https://api.mojang.com/users/profiles/minecraft/${username}`);
const json = await response.json();
uuidP = json.id;
}
request();
console.log(num); //returns 1234
console.log(uuidP); //returns udefined