Skip to content

QuizNot attempted

super() in constructors

In a subclass constructor, what happens if you use this before calling super()?
1–4 to choose, Enter to submit
Show answer & explanation

Correct answer:

  • ReferenceError: the instance does not exist until the parent constructor creates it
  • In a derived class the parent constructor allocates the object, so until super() returns this is uninitialized and touching it throws ReferenceError.
  • Not 'an empty object': there is no object yet.
  • Not 'calls super() for you': only an omitted constructor gets an implicit super(...args).
  • Not 'TypeError only in strict mode': class bodies are always strict, and the error is a ReferenceError.