Error Handling and Debugging

Last Updated :
Discuss
Comments

Question 1

What is the purpose of the try...catch block in JavaScript?

  • A

    To handle asynchronous code

  • B

    To handle errors during code execution

  • C

    To stop the execution of a program

  • D

    To skip specific lines of code

Question 2

Which statement is used to manually throw an error in JavaScript?

  • A

    throw

  • B

    raise

  • C

    error

  • D

    reject

Question 3

What is the Error object used for?

  • A

    To create custom error messages

  • B

    To debug code by printing logs

  • C

    To represent runtime errors in JavaScript

  • D

    To pause code execution

Question 4

What is the output of the following code?

JavaScript
try {
    console.log(a);
} catch (e) {
    console.log(e.message);
}


  • A

    a is not defined

  • B

    ReferenceError: a is not defined

  • C

    Undefined

  • D

    Throws no error

Question 5

Which console method is used to display a table of data?

  • A

    console.log()

  • B

    console.error()

  • C

    console.data()

  • D

    console.table()

Question 6

What happens if there is no catch block for a thrown error?

  • A

    The program continues execution

  • B

    The error is ignored

  • C

    The program crashes or stops execution

  • D

    A warning is displayed in the console

Question 7

Which of the following methods halts the browser's execution to inspect the code?

  • A

    debugger

  • B

    console.stop()

  • C

    break()

  • D

    console.inspect()

Question 8

What is the purpose of the finally block in error handling?

  • A

    Executes only if an error occurs


  • B

    Executes only if no error occurs

  • C

    Executes after the try and catch blocks, regardless of errors

  • D

    Stops the error from propagating further

Question 9

Which of the following is NOT a console method?

  • A

    console.time()

  • B

    console.warn()

  • C

    console.info()

  • D

    console.alert()

Question 10

What is the primary advantage of using a linter like ESLint in debugging?

  • A

    Automatically fixes all errors in code

  • B

    Highlights potential errors and enforces coding standards

  • C

    Pauses execution of the code

  • D

    Provides runtime debugging tools

There are 10 questions to complete.

Take a part in the ongoing discussion