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 is the result of `console.log(jim.__proto__.age);` after defining a Person prototype property?

  1. 29

  2. 18

  3. TypeError

  4. undefined

The correct answer is: 29

To understand the correct answer, it's important to look at how JavaScript's prototypal inheritance works and how properties are accessed on objects. In JavaScript, when an object is created, it can inherit properties from its prototype. When you define a property on the prototype of a constructor function (like Person), all instances of that object can access that property through their prototype chain. If we assume that the Person prototype has an `age` property set to 29, then any instance of Person, such as `jim`, will be able to access this property through `jim.__proto__`. The `__proto__` property refers to the prototype of the object (`jim` in this case). Hence, when `console.log(jim.__proto__.age);` is executed, it will look up the inheritance chain and find the `age` property defined on the Person prototype, returning its value, which is 29. Given this context, if the prototype was indeed set up properly to contain an `age` property equal to 29, then logging `jim.__proto__.age` would correctly output 29.