Instructions

  • 1. Your final score will reflect your grasp of the concepts—approach each question with precision.
  • 2. Thoroughly review each solution before proceeding to ensure full understanding.
  • 3. Final results will be available after submission to provide insights into areas for further improvement.
  • 4. Maintain academic integrity—plagiarism undermines learning and professional growth.
  • 5. Once submitted, responses are final, so ensure you’re confident in your answers.
  • 6. These challenges are designed to test practical knowledge; apply your skills as you would in real-world scenarios.

All Problems

Question

Action

What is error propagation?

View

How can you propagate an error in JavaScript?

View

How do you create a custom error in JavaScript?

View

How do you catch different types of errors in JavaScript?

View

Which of the following will catch an error in an asynchronous function?

View

How do you add a custom property to an Error object?

View

What is the main advantage of creating custom error types?

View

Which of the following is a valid example of a custom error class in JavaScript?

View

How can you ensure that a custom error inherits the stack trace from the built-in Error class?

View

Which error is used for range violations in JavaScript, such as calling a function with invalid numbers?

View

What is error propagation?

The process of throwing an error multiple times
Passing errors from a catch block to another part of the program
Re-throwing errors to higher try/catch blocks
Ignoring errors and continuing execution

How can you propagate an error in JavaScript?

By rethrowing the error in the catch block
By logging the error and terminating the program
By catching the error and fixing it
By using throw in the finally block

How do you create a custom error in JavaScript?

By using the new Error() constructor
By using the throw keyword without an error message
By overriding the built-in Error class
Both a and c

How do you catch different types of errors in JavaScript?

Use multiple catch blocks
Use if conditions inside the catch block
JavaScript only allows one type of error
Use a switch statement

Which of the following will catch an error in an asynchronous function?

Wrapping the asynchronous code in a try/catch block
Using .catch() on the promise returned by the function
Ignoring the error and retrying
Both a and b

How do you add a custom property to an Error object?

It is not possible to add properties to Error objects
By directly assigning the property after creating the error object
By overriding the Error object’s constructor
By using the Object.defineProperty method

What is the main advantage of creating custom error types?

It makes the code more complex
It allows you to define meaningful error messages and properties
It prevents any errors from occurring
It is faster than using built-in errors

Which of the following is a valid example of a custom error class in JavaScript?

class MyError extends Error {}
class MyError extends String {}
class MyError extends Number {}
class MyError extends Boolean {}

How can you ensure that a custom error inherits the stack trace from the built-in Error class?

By calling super(message) in the constructor of the custom error class
By not inheriting from Error
By manually assigning the stack trace
By logging the error

Which error is used for range violations in JavaScript, such as calling a function with invalid numbers?

SyntaxError
TypeError
RangeError
ReferenceError