XJavascript.com
Toggle Menu
Home
Online Javascript Compiler
Tutorials
JavaScript Tutorials
TypeScript Tutorials
Blog
All Posts
JavaScript Error Handling
Explore exceptions,try-catch blocks,and debugging best practices.
1. What is the correct syntax to handle errors in JavaScript?
try...catch
try...handle
catch...try
error...handle
2. Which block is used to enclose code that might throw an error?
try
catch
finally
throw
3. Which error type occurs when accessing an undefined variable?
SyntaxError
ReferenceError
TypeError
RangeError
4. Which block handles errors thrown in the try block?
try
catch
finally
throw
5. What happens if an error is thrown in a try block with no catch block?
The script continues execution
The error is ignored
The script stops executing
The finally block runs immediately
6. Which property of an error object contains the error message?
msg
message
text
description
7. What is the output of: try { throw 'oops'; } catch(e) { console.log(e); } finally { console.log('done'); }
'oops' then 'done'
'done' then 'oops'
'oops' only
'done' only
8. Which error is thrown when a value is not of the expected type (e.g., calling a string as a function)?
SyntaxError
ReferenceError
TypeError
EvalError
9. Which of the following are valid error-handling constructs in JavaScript?
try...catch
try...finally
catch...finally
try...catch...finally
10. What can be thrown using the 'throw' statement?
An Error object
A string
A number
A boolean
11. Which are built-in error types in JavaScript?
Error
SyntaxError
CustomError
ReferenceError
12. Which properties do standard Error objects have?
name
message
stack
code
13. How can you handle errors with async/await?
try...catch around await
.catch() method on the promise
throw statement inside async function
try...handle block
14. The finally block is optional in a try/catch structure.
True
False
15. try...catch can only handle errors in synchronous code.
True
False
16. Throwing an error stops execution of the current function.
True
False
17. The Error constructor requires a message parameter.
True
False
18. What keyword defines a block that executes after try/catch, regardless of errors?
19. What property of an Error object returns a string representing the call stack trace?
20. Name the error type thrown when a number is outside the allowable range (e.g., new Array(-1)).
Reset
Answered 0 of 0 — 0 correct