フリー問題

Salesforce Certified JavaScript Developer のフリー問題 14 / 20 問目

問題文

A team needs callers to distinguish a validation failure from other failures with instanceof, and the log must show a distinctive name. What should the team define?

選択肢

  1. A string that starts with a fixed prefix naming the category, thrown directly to the caller.
  2. A plain object with a code property, thrown as it is, because throwing an object keeps the payload small and instanceof still works against the constructor that produced the object literal at the point where it was created.
  3. A class that extends Error, calls super with the message and sets its own name in the constructor.
  4. A function that returns an Error object without throwing it, because returning the error lets the caller decide whether to treat it as a failure and instanceof then works on the returned value.

解答・解説を確認するには

正解と解説の確認、回答の記録には無料登録が必要です。登録すると演習モードでフリー問題に回答し、正誤と解説をその場で確認できます。