CRT-600 practice question 19 of 30

Refer to the code below: Function Person(firstName, lastName, eyecolor) { this.firstName =firstName; this.lastName = lastName; this.eyeColor = eyeColor; } Person.job = ‘Developer’; const myFather = new Person(‘John’, ‘Doe’); console.log(myFather.job); What is the output after the code executes?

Full set: 223 questions
Answer options
A: ReferenceError: eyeColor is not defined Correct answer
B: ReferenceError: assignment to undeclared variable “Person”
C: Developer
D: Undefined
Correct Answer:
A. ReferenceError: eyeColor is not defined
Explanation

The script will throw a ReferenceError and halt execution. The Person constructor function has a parameter named eyecolor (with a lowercase 'c'). Inside the function, the line this.eyeColor = eyeColor; attempts to access a variable named eyeColor (with an uppercase 'C'). Because JavaScript is case-sensitive, the variable eyeColor has not been declared or defined within this scope. This causes a ReferenceError to be thrown when the code attempts to instantiate the object with new Person(‘John’, ‘Doe’). Consequently, the console.log statement is never reached.

Why Incorrect

B. ReferenceError: assignment to undeclared variable “Person” This is incorrect because Person is properly declared as a function, and assigning a static property (Person.job) to a function object is a valid operation in JavaScript.
C. Developer This is incorrect because the script execution halts due to the ReferenceError before the console.log is reached. Additionally, .job is a static property on the Person constructor, not on instances like myFather.
D. Undefined This is incorrect because the ReferenceError prevents the console.log(myFather.job) line from ever executing. The script terminates with an error, not by printing undefined.

References

1. ECMAScript® 2023 Language Specification (ECMA-262

14th edition)

Section 7.1

"Static Semantics: AllPrivateIdentifiersValid". This section implicitly relies on identifier resolution

where case-sensitivity is fundamental. The specification states that identifiers are sequences of characters

and comparison is exact and case-sensitive. The identifier eyecolor is distinct from eyeColor.

2. ECMAScript® 2023 Language Specification (ECMA-262

14th edition)

Section 6.2.4

"The Reference Record Specification Type". When an identifier like eyeColor cannot be resolved in the current lexical environment

it results in an "unresolvable" reference

which leads to a ReferenceError being thrown.

3. MDN Web Docs

JavaScript Reference: ReferenceError. "A ReferenceError is thrown when a variable that doesn't exist (or hasn't yet been initialized) in the current scope is referenced." This directly describes the situation where the code attempts to use the undeclared variable eyeColor.

4. Flanagan

D. (2020). JavaScript: The Definitive Guide (7th ed.). O'Reilly Media. Chapter 3

"Types

Values

and Variables

" Section 3.9.2

"Variable Scope

" explains that an attempt to read the value of a non-existent variable results in a ReferenceError. The case-sensitivity of variable names is a core aspect of this rule.

Scroll to Top