FlashKeepers

JavaScript · JavaScript · College and University

JavaScript Error Handling and Debugging

Try catch blocks, custom error types, and common debugging techniques in JavaScript, each explained with a short example.

About this set

29 basic cards for JavaScript JavaScript. It opens with "What is the syntax for a try-catch block?" and "What happens if an error is thrown inside try without a catch?". More College and University decks are listed below.

29 cards · basic cards · AI-written, checked twice. Edit anything.

Study this set free Look inside first Get FlashKeepers for iPhone

Opens in your browser, no account. Get the iPhone and iPad app · Android app

What is the syntax for a try-catch block?
Show answertry { code that might fail } catch (error) { handle error }
What happens if an error is thrown inside try without a catch?
Show answerThe script stops, the error propagates up, and execution halts unless caught higher up
Name three properties available on an Error object
Show answermessage, name, stack
What error does accessing an undefined variable throw?
Show answerReferenceError
What error does calling a non-function throw?
Show answerTypeError
What error is thrown for invalid JSON syntax?
Show answerSyntaxError
What is the purpose of the finally block?
Show answerCode that runs after try or catch, regardless of whether an error occurred
How do you manually throw an error?
Show answerUse the throw keyword: throw new Error('message') or throw someValue
How do you create a custom error type?
Show answerExtend the Error class: class MyError extends Error { constructor(message) { super(message) } }
What does the stack property of an Error contain?
Show answerA string showing the call stack at the point the error was thrown, useful for debugging
What is console.log primarily used for?
Show answerPrinting general information to the console for debugging
What is the difference between console.error and console.warn?
Show answerconsole.error is for errors (red), console.warn is for warnings (yellow or orange)
What does the debugger statement do?
Show answerPauses code execution at that line when developer tools are open, allowing step-through inspection
How do you catch errors from a Promise?
Show answerUse .catch() method: promise.catch(error => { handle error })
How do you use try-catch with async/await?
Show answertry { const result = await someAsyncFunction() } catch (error) { handle error }

14 more cards in the app

Study this set free