A. dog1.wagTail() === dog2.wagTail() true B. dog1.wagTail === dog2.wagTail false C. dog1.bark === dog2.bark true D. Object.getPrototypeOf(dog1) === Object.getPrototypeOf(dog2) true E. dog1.constructor === dog2.constructor true
console.log(counterOne.count, counterTwo.count); // will log 2, 3 // because Object.create() creates a new object with the prototype of the object passed in // so the prototype of counterTwo is counterOne // and if we mutate the count property of counterTwo // it will create a new property on counterTwo // instead of mutating the count property of counterOne
const freddie = newChameLeon('green'); freddie.changeColor('orange'); // will log TypeError: freddie.changeColor is not a function // because changeColor is a static method // and can only be called on the class itself
A. Object.getPrototypeOf(user) === User.prototype; true B. Object.getPrototypeOf(user) === Object.getPrototypeOf(User); false, because Object.getPrototypeOf(User) is Function.prototype C. user.prototype === User.prototype; false, because user is an instance of User, not a class, so it doesn’t have a prototype property D Object.getPrototypeOf(User) === User.constructor false, because User.constructor is Function
Generators & Iterators
Question 21
What gets logged?
1 2 3 4 5 6 7 8 9 10 11
function* count() { yield1; yield2; return3; }
for (const num ofcount()) { console.log(num); }
// will log 1, 2, because the return value of the generator is ignored
Question 22
To create a custom iterable object in JavaScript, the object must implement the Symbol.iterator method that returns an iterator.
The iterator must implement what methods?
A. next // true B. iterator // false C. iterate // false D. forEach // false E. none // false
Question 23
What gets logged?
1 2 3 4 5 6 7 8 9 10 11 12 13 14
asyncfunction* range(start, end) { for (let i = start; i <= end; i++) { yieldPromise.resolve(i); } }
(async () => { const gen = range(1, 3); forawait (const num of gen) { console.log(num); } })();
A. By invoking fn // false B. By explicitly setting fn to null // true C. It is automatically garbage collected when the outer function is called // false D. It depends on the JavaScript engine // false
Question 27
Which of the following statements are true?
1 2 3 4
let obj = { a: { b: 2 } }; let ref = obj.a;
obj = null;
A. The object {b: 1} will be garbage collected // false B. ref still references the object {b: 1}, so it will not be garbage collected // true C. The entire obj object is retained in the memory due to the reference ref // false D. Setting obj to null frees all memory associated with it // false
Question 28
You can get a list of all keys in a WeakMap using its keys method, but you can’t get its values or entries. // false
Question 29
When will each user be eligible for garbage collection?
1 2 3 4 5 6
functionmyFunc() { for (let i = 0; i < 10; i++) { const user = { name: 'Alice' }; return user; } }
A. Immediately after each iteration. // true B. After the loop completes. // false C. Only if explicitly set to null within the loop. // false D. When the function containing the loop finishes executing. // false
Question 30
What gets logged?
1 2 3 4 5 6 7 8 9 10 11 12 13
const obj = { bar() { console.log(this); }, };
setTimeout(() => obj.bar(), 0);
queueMicrotask(() => { delete obj.bar; });
// will log type error: obj.bar is not a function
Modules
Question 31
Match each module loading mechanism with its correct characteristic.
CommonJS: Used mainly in server-side contexts, this approach loads modules sequentially.
AMD: Focuses on client-side asynchronous loading, allowing modules to be fetched and executed in a non-blocking manner.
UMD: supports various environments, accommodating both server and client-side usages.
require('./file1.js'); import'./file2.mjs'; // import will be hoisted to the top import'./file3.mjs';
functiongetModule() { import('./file4.mjs'); // this is a dynamic import, it will return a promise, and the import will be executed asynchronously require('./file5.js'); }
Which of the following statements correctly describe the differences between require and import?
A. require can be called conditionally, while the import statement can not. // true B. import statements are hoisted, but require statements are not. // true C. require synchronous loads modules, while import can load modules asynchronously. // true D. import allows for static analysis and tree shaking, but require does not. // true
Numbers
Question 34
What gets logged?
1 2 3 4
let number = 0; console.log(number++); // 0 console.log(++number); // 2 console.log(number); //2
const a = isNaN('5.2' + 2); // false const b = isNaN(parseInt(a)); // true const c = isNaN(parseFloat(a)); // true const d = isNaN('1 * 2' * 2); // true console.log(a, b, c, d);
Question 37
Match the equivalent values
1 2 3 4
// 'ff' === 255..toString(16); // '11111111' === 255['toString'](2); // SyntaxError 255.toString(10); This will throw a syntax error because the dot is interpreted as a decimal point // '255' === 255['toString'](10);
Miscellaneous
Question 38
Which methods will return the value “Hello world”?
A. myMap.get('greeting') // false B. myMap.get(myFunc) // true C. myMap.get(() => "greeting") // false D. myMap.get(myFunc()) // false E. None of the above // false
Question 39
What does the person object look like after executing the following code?
const result = team.members.map(getInfo); // [ 'New York', 'Unknown', "New York", 'Unknown' ]
Question 45
Match the code to correct error it would throw
1 2 3 4 5
newArray(-1); // RangeError: Invalid array length 25.toString(); // SyntaxError: Invalid or unexpected token [].reduce((acc, cur) => acc + cur); // TypeError: Reduce of empty array with no initial value const { a: b = c} = {a: undefined, c: 12} // ReferenceError: c is not defined const a = {b : 1}; console.log((a ?? 1) || b); // No error
Question 46
Match the date methods with the correct values when invoked on new Date()
const greeting = 'Thank you for coming to my workshop!'; thankYouTag`This is the last question! ${greeting}`; // [ 'This is the last question! ', '' ] 'Thank you for coming to my workshop!'