Which expression creates an object using the literal syntax with two properties, name and age?
Classless Objects
Question · Easy
Given const obj = { 'first-name': 'Ada' };, which statement correctly reads the property?
What does the following code log? const o = { a: 1 }; delete o.a; console.log(o.a);
Tech Exam Prep Podcast
Listen on Spotify
Podcast
Which expression safely reads street when the chain may be missing, returning undefined instead of throwing? const data = {};
Question · Medium
What is the result of the following expression? const car = { brand: 'Fiat' }; console.log('brand' in car, 'model' in car);
Which method returns an array of a plain object's own enumerable property names?
What does this code log? const a = { x: 1 }; const b = { x: 1 }; console.log(a === b);
After the following code runs, what does original.nested.value equal? const original = { nested: { value: 1 } }; const copy = { ...original }; copy.nested.value = 99;
Which call merges the properties of source into target, mutating target and returning it?
What does the following log? const counter = { count: 5, increment() { this.count++; } }; counter.increment(); console.log(counter.count);
What does this code log? const temp = { _c: 0, set celsius(v) { this._c = v; }, get fahrenheit() { return this._c * 9 / 5 + 32; } }; temp.celsius = 100; console.log(temp.fahrenheit);
Which method creates a new object whose prototype is the object proto?
What does this constructor-function code log? function Point(x, y) { this.x = x; this.y = y; } const p = new Point(2, 3); console.log(p.x + p.y);
A factory function for creating user objects is best described as a function that:
What does this code log? const obj = {}; Object.defineProperty(obj, 'id', { value: 7, writable: false }); obj.id = 99; console.log(obj.id);
Question · Hard
Which method prevents new properties from being added but still allows existing properties to be changed or deleted?
What does this code log after Object.freeze? 'use strict'; const cfg = Object.freeze({ debug: false }); try { cfg.debug = true; } catch (e) { console.log('blocked'); } console.log(cfg.debug);
What does the following log? const proto = { greet() { return 'hi'; } }; const obj = Object.create(proto); console.log(obj.greet(), obj.hasOwnProperty('greet'));
Which method changes the prototype of an existing object at runtime?
What does this code log? const person = { name: 'Lee', age: 30 }; for (const key in person) { if (person.hasOwnProperty(key)) console.log(key); }
What does Object.entries({ a: 1, b: 2 }) return?
What does this code log? const key = 'role'; const user = { [key]: 'admin' }; console.log(user.role);
What does this code log? const a = { val: 10 }; const b = a; b.val = 20; console.log(a.val);
Which technique produces a deep clone of an object that contains nested objects, with no shared references?
What does this code log? const obj = { a: 1 }; Object.seal(obj); obj.a = 2; obj.b = 3; console.log(obj.a, obj.b);
What does this code log? class Animal { constructor(name) { this.name = name; } speak() { return this.name + ' makes a sound'; } } const a = new Animal('Rex'); console.log(a.speak());
Classes And Class Based Approach
What does this code log? class Box {} const b = new Box(); console.log(b instanceof Box, b instanceof Object);
Given a class field declared with class field syntax, what does this log? class Counter { value = 0; bump() { this.value += 1; } } const c = new Counter(); c.bump(); c.bump(); console.log(c.value);
What does this code log? class Temperature { #celsius = 0; set celsius(v) { this.#celsius = v; } get fahrenheit() { return this.#celsius * 1.8 + 32; } } const t = new Temperature(); t.celsius = 25; console.log(t.fahrenheit);
What does this inheritance code log? class Shape { area() { return 0; } } class Square extends Shape { constructor(s) { super(); this.s = s; } area() { return this.s * this.s; } } console.log(new Square(4).area());
In a subclass constructor that uses extends, what happens if you access this before calling super()?
What does this code log? class Base { greet() { return 'Base'; } } class Sub extends Base { greet() { return super.greet() + '+Sub'; } } console.log(new Sub().greet());
What does this code log? class MathUtil { static square(n) { return n * n; } } console.log(MathUtil.square(5));
What does this code log? class Widget { static count = 0; constructor() { Widget.count++; } } new Widget(); new Widget(); console.log(Widget.count);
Which statement best relates ES6 class syntax to constructor functions?
What does this class expression code log? const Rectangle = class { constructor(w, h) { this.w = w; this.h = h; } get area() { return this.w * this.h; } }; console.log(new Rectangle(3, 4).area);
What does this code log? class User { constructor(name) { this.name = name; } } class Admin extends User { constructor(name) { super(name); this.role = 'admin'; } } const a = new Admin('Mia'); console.log(a.name, a.role);
Are class declarations hoisted in a usable way like function declarations?
What does this code log? class A { static create() { return new this(); } hello() { return 'A'; } } class B extends A { hello() { return 'B'; } } console.log(B.create().hello());
What does this code log? class Stack { items = []; push(x) { this.items.push(x); return this; } } const s = new Stack(); s.push(1).push(2); console.log(s.items.length);
What does this code log? class Vehicle { constructor() { this.wheels = 4; } } class Motorcycle extends Vehicle { constructor() { super(); this.wheels = 2; } } console.log(new Motorcycle().wheels);
What does this code log? class Repo { #data = []; add(x) { this.#data.push(x); } get size() { return this.#data.length; } } const r = new Repo(); r.add('x'); console.log(r.size, r.data);
What does this code log? class Logger { log = () => 'instance arrow'; } const l = new Logger(); const fn = l.log; console.log(fn());
What does this code log? class Shape { describe() { return 'shape'; } } const s = new Shape(); console.log(Object.getPrototypeOf(s) === Shape.prototype);
What does this code log? class Account { constructor(balance) { this._balance = balance; } get balance() { return this._balance; } set balance(v) { if (v < 0) return; this._balance = v; } } const acc = new Account(100); acc.balance = -50; console.log(acc.balance);
What does this code log? class A { who() { return 'A'; } } class B extends A {} class C extends B {} console.log(new C().who());
What does this code log? class Greeter { constructor(name) { this.name = name; } static fromUpper(s) { return new Greeter(s.toUpperCase()); } } console.log(Greeter.fromUpper('ada').name);
Loading more…