Question 71
HardWhat is the output of this program?
const m = new Map([[, ], [, ]]);
o = { : , : };
.(m., .(o)., m.(), o[]);
Popular companies
Prepare company by company
Hiring pattern, syllabus, past questions and mocks for each company.
All companiesPractice by subject
Programming Languages
What is the output of this program?
const m = new Map([[, ], [, ]]);
o = { : , : };
.(m., .(o)., m.(), o[]);
2 1 a b
2 2 a a
2 1 b b
1 1 a b
Sign up free to see the answer and a step-by-step explanation.
What is the output of this program?
function Person(n) { this.n = n; }
Person.prototype.hi = function () { return "hi " + this.n; };
const a = new Person("x");
const b = Object.create(a);
b.n = "y";
console.log(a.hi(), b.hi(), Object.getPrototypeOf(b) === a, b.hasOwnProperty("hi"));
hi x hi y false false
hi x hi y true false
Sign up free to see the answer and a step-by-step explanation.
What is the output of this program?
const s = "abcabc";
console.log(s.replace("a", "X"), s.replaceAll("a", "X"), s.split("b"), [..."héllo"].length, "abc".at(-1));
Xbcabc XbcXbc [ 'a', 'cab', 'c' ] 5 c
Xbcabc XbcXbc [ 'a', 'ca', 'c' ] 5 c
Sign up free to see the answer and a step-by-step explanation.
What is the temporal dead zone in JavaScript?
A period when timers can't run
Code after a return
The time between entering a scope and a let/const declaration, when accessing the variable throws a ReferenceError
A garbage-collection pause
Sign up free to see the answer and a step-by-step explanation.
Why does 'this' inside a regular function passed as a callback (such as setTimeout(obj.method, 0)) often not refer to obj?
It always refers to obj
this is set by how a function is called, and the callback is called without obj
setTimeout deletes objects
Methods can't be callbacks
Sign up free to see the answer and a step-by-step explanation.
What is event bubbling in the DOM?
An event on an element also fires on its ancestors, from the target outwards
Events run in random order
Events are cancelled automatically
Events fire only on the document
Sign up free to see the answer and a step-by-step explanation.
What does 'use strict' change about assigning to an undeclared variable?
Nothing
It throws a ReferenceError instead of creating a global variable
It converts it to a constant
It creates a local variable
Sign up free to see the answer and a step-by-step explanation.
What is the difference between microtasks and macrotasks in the event loop?
All queued microtasks (promise callbacks) run before the next macrotask (timers, I/O)
Macrotasks always run first
They run in parallel
There is no difference
Sign up free to see the answer and a step-by-step explanation.
What is a WeakMap useful for?
Faster iteration
Storing primitives as keys
Sorting keys
Associating data with objects without preventing those objects from being garbage-collected
Sign up free to see the answer and a step-by-step explanation.
What does Array.prototype.reduce return for an empty array with no initial value?
An empty array
It throws a TypeError
undefined
0
Sign up free to see the answer and a step-by-step explanation.
hi x hi x true false
hi x hi y true true
Xbcabc XbcXbc [ 'a', 'ca', 'c' ] 6 c
XbcXbc XbcXbc [ 'a', 'ca', 'c' ] 5 c