Monday, 27 July 2020

Really confused as to what's going on with this async/await function.

It's a pretty simple that function that hashes a password.async function createPassword(password) { try { const hashedPassword = await bcrypt.hash(password, 11).then(data => data); console.log('Logged: ', hashedPassword); return hashedPassword; } catch (err) { console.log(err); } } console.log('Returned: ', createPassword('hello')); I am so confused as to why logging 'hashPassword' works but returning it doesn't. On top of that, why does the console.log execute last? Any help would be greatly appreciated.

Submitted July 28, 2020 at 01:28AM by Sweeterman3

No comments:

Post a Comment