This section explores Error Handling and Debugging in JavaScript, focusing on try-catch, finally, custom errors, console methods, and debugging tools for effective problem resolution.
Question 1
What is the purpose of the try...catch block in JavaScript?
To handle asynchronous code
To handle errors during code execution
To stop the execution of a program
To skip specific lines of code
Question 2
Which statement is used to manually throw an error in JavaScript?
throw
raise
error
reject
Question 3
What is the Error object used for?
To create custom error messages
To debug code by printing logs
To represent runtime errors in JavaScript
To pause code execution
Question 4
What is the output of the following code?
try {
console.log(a);
} catch (e) {
console.log(e.message);
}
a is not defined
ReferenceError: a is not defined
Undefined
Throws no error
Question 5
Which console method is used to display a table of data?
console.log()
console.error()
console.data()
console.table()
Question 6
What happens if there is no catch block for a thrown error?
The program continues execution
The error is ignored
The program crashes or stops execution
A warning is displayed in the console
Question 7
Which of the following methods halts the browser's execution to inspect the code?
debugger
console.stop()
break()
console.inspect()
Question 8
What is the purpose of the finally block in error handling?
Executes only if an error occurs
Executes only if no error occurs
Executes after the try and catch blocks, regardless of errors
Stops the error from propagating further
Question 9
Which of the following is NOT a console method?
console.time()
console.warn()
console.info()
console.alert()
Question 10
What is the primary advantage of using a linter like ESLint in debugging?
Automatically fixes all errors in code
Highlights potential errors and enforces coding standards
Pauses execution of the code
Provides runtime debugging tools
There are 10 questions to complete.