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 questionsThe 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.
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.
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.
Keep practicing
Take the free CRT-600 practice test
Ten exam-style questions with answers and explanations, plus the exam facts and study guides.
More questions
Other CRT-600 practice questions
- Question 2A developer has the function, shown below, that is called when a page loads. function onl…
- Question 3A developer needs to test this function: 01 const sum3 = (arr) => ( 02 if (!arr.length) r…
- Question 4Refer to the code below: Const resolveAfterMilliseconds = (ms) => Promise.resolve ( setTi…
- Question 10Refer to the following code block: class Animal{ constructor(name){ this.name = name; } m…
- Question 11A developer needs to debug a Node.js web server because a runtime error keeps occurring a…
- Question 12Refer to the string below: const str = 'Salesforce'; Which two statements result in the w…
