S
24

PSA: My first time using async/await in JavaScript broke everything in weird ways

Tried to refactor a basic form validation script with async/await last night and suddenly my page just showed 'undefined' for all the error messages. Turns out I forgot to use 'await' inside the main function call for like 3 hours. Learned that checking your console errors line by line in Chrome DevTools saves way more time than guessing what went wrong. Has anyone else had a simple async fix turn into a total mess?
2 comments

Log in to join the discussion

Log In
2 Comments
the_robin
the_robin10d agoTop Commenter
Used to think promises were overcomplicating things but this post totally changed my mind.
3
jakel36
jakel3610d ago
The classic forgot-to-await situation got me on my first async form too, took me a solid 2 hours of console.logging everything before I spotted it. Always stick a .catch on those async calls or wrap them in try/catch so you get real error messages instead of 'undefined'.
1