Go Pro Sign Up Login

Buy Now and unlock this series

$

39

.99

$

24

.99

yours forever

Become a Pro and unlock everything

$

24

.99

per month

Async Await

Downloads

Become a pro to download code and videos

Starting Code

Final Code

Comments

User avatar

Samuel Pilay

over 2 years ago [edited]

I want to know how to assign the value of the promise to a variable that is out of the await function

Example:

const chargeCard = () => new Promise((resolve, reject) => { // card is valid // reject("fail!!!"); if (true) { return resolve(true); } return resolve(false); });

var fgo = null;

const chargeCC = async ccNumber => { try { const res = await chargeCard(ccNumber); fgo = await chargeCard(ccNumber); console.log(res); return res; } catch (error) { console.log(error); } };

Want to join the conversation?

Become a Pro member today!