Question 1
What is an object in JavaScript, most precisely?
WhyA class is one way to make objects, and an object is not a blueprint; the blueprint is the class. Arrays are themselves objects, not the other way round.
30 questions across the whole course. Every option is explained the moment you answer, right or wrong, because the explanation is the point and the score is not. Nothing is recorded.
Question 1
What is an object in JavaScript, most precisely?
WhyA class is one way to make objects, and an object is not a blueprint; the blueprint is the class. Arrays are themselves objects, not the other way round.
Question 2
What does bus.owner evaluate to when the object has no owner property?
WhyA missing property is undefined, and reading it is not an error. The error comes one step later, if you then read a property of that undefined.
Question 3
Which of these does const prevent?
Whyconst constrains the binding, not the value. Freezing the contents is Object.freeze.
Question 4
After const b = a where a is an object, what is true?
WhyAssignment copies the reference. { ...a } gives a shallow copy; structuredClone(a) gives a deep one.
Question 5
What makes a function a "method"?
WhyThere is no distinction in the function itself. Where it is stored is the only difference.
Question 6
Given const f = obj.method; f(); in strict mode, what is this inside the call?
const obj = {
name: 'Jibowu park',
method() { return this; },
};
const f = obj.method;
console.log(obj.method());
console.log(f());
Output
WhyThere is no object before a dot at the call site, so there is no owner. Sloppy mode would have substituted the global object, which is the behaviour strict mode removed.
Question 7
Why should you never write an object literal method as an arrow function?
WhyThe borrowing that makes arrows perfect as callbacks inside a method makes them useless as the method itself.
Question 8
Which fix keeps this correct when passing a method as a callback, using the exact same function object each time?
WhyEach .bind() returns a new function, so removeEventListener would not match one created inline. Store the bound version.
Question 9
What is the main advantage of a factory function over a class?
Whyinstanceof is a class advantage, not a factory one. Factories win on closure privacy and on deciding what to return.
Question 10
What is the cost of a factory function that defines its methods inline?
WhyThis is exactly the problem prototypes solve, which is why class exists.
Question 11
Which is NOT one of the four things new does?
WhyNothing is copied. The link to Ctor.prototype is what gives the object access to the methods.
Question 12
What happens when you call a class without new?
WhyClasses have that check built in. Old constructor functions had to test new.target themselves.
Question 13
What does property lookup do when a property is not on the object?
WhyThis one mechanism is the whole of JavaScript inheritance.
Question 14
What is the difference between 'x' in obj and Object.hasOwn(obj, 'x')?
WhyWhen you are filtering out inherited members, Object.hasOwn is the one you want.
Question 15
What will this print, and why?
function Bus(plate) { this.plate = plate; }
Bus.prototype.faults = [];
const a = new Bus('LAG-441-XA');
const b = new Bus('ABJ-772-KM');
a.faults.push('cracked windscreen');
console.log(a.faults);
console.log(b.faults);
Output
WhyAssignment writes to the instance, but push mutates the one shared array on the prototype. Per-instance state belongs in the constructor.
Question 16
In a class body, where do fields and methods end up?
WhyData per object, behaviour shared. It is exactly the constructor-plus-prototype pattern from lesson 05.
Question 17
What separates members inside a class body?
WhyA class body is not an object literal. A trailing comma after a method is a syntax error, and it is the most common typo when moving from literals to classes.
Question 18
What does JSON.stringify do with a #private field?
WhyPrivate fields are invisible to Object.keys, spread and JSON.stringify alike. Use toJSON() when you need a specific serialised shape.
Question 19
What happens if you write obj.#field outside the class that declares it?
WhyThe restriction is enforced at parse time, which is stricter than most languages and why you cannot poke at private fields from the console.
Question 20
What does a leading underscore, as in this._balance, actually enforce?
WhyIt communicates intent to humans and nothing to the language. Use # in new code.
Question 21
When should a computed value be a getter rather than a method?
WhyCallers assume reading a property is cheap and harmless. If it is slow or changes something, make it a method so the cost is visible.
Question 22
Why does this throw a RangeError about the call stack?
class Broken {
set label(value) {
this.label = value.trim();
}
}
try { new Broken().label = ' x '; }
catch (err) { console.log(err.name); }
Output
WhyStore in a differently named field, usually a private one, so the setter has somewhere to put the value.
Question 23
What should a getter do when it would otherwise return a private array?
WhyHanding out the real array undoes the encapsulation you built with the private field.
Question 24
Where does a static member live?
WhyThat is why instance.staticThing is undefined: the instance chain leads to the prototype, not to the class.
Question 25
Inside a static method, what is this?
WhyThis is why static make() { return new this(...) } keeps working in subclasses, where hard-coding the parent class name would not.
Question 26
What must a subclass constructor do before touching this?
Whythis does not exist until super() has run, and omitting the call entirely is also an error.
Question 27
What does super.method() do?
WhyIt is what lets an override extend the parent’s behaviour rather than replace it, as in [...super.checklist(), 'extra'].
Question 28
Which is the clearest sign that inheritance was the wrong tool?
WhyThat is a substitutability failure. Either the parent promised too much, or the relationship is "has a" rather than "is a".
Question 29
You have buses that may have air conditioning, may have a roof rack, or may have both. What does a class hierarchy force?
WhyTwo independent axes of variation are the textbook signal for composition. Each capability becomes a part the object holds.
Question 30
Which SOLID principle does a growing switch (thing.type) in shared code violate first?
WhyThe fix is polymorphism: let each type answer for itself, so a new type is new code rather than an edit to old code.
Newsletter
Occasional notes on shipping software with AI agents. No schedule, no filler, unsubscribe in one click.