Prepare for the Salesforce JavaScript Developer Exam. Utilize comprehensive quizzes, flashcards, and multiple choice questions with hints and explanations. Boost your exam readiness!

Practice this question and more.


What are the two main properties of an error object that's passed as an argument to catch in a try...catch construct?

  1. name and stacktrace

  2. title and message

  3. title and stack

  4. name and message

The correct answer is: name and message

In JavaScript, when an error is thrown and subsequently caught using a try...catch construct, the error object that is passed into the catch block contains valuable information about the error. The two main properties of this error object that are typically accessed are "name" and "message". The "name" property indicates the type of the error, which can be useful for determining the kind of issue that occurred (e.g., SyntaxError, ReferenceError). The "message" property provides a description of the error, giving additional context about what went wrong. This information can help developers quickly identify and troubleshoot issues in their code. While there are other properties like "stack" that can be useful for debugging, the fundamental properties that are most commonly available and relevant in a catch block are "name" and "message". This makes the choice that highlights these two properties the most accurate one in the context of what is essential when handling errors in JavaScript.