Question 51
MediumWhat is a closure?
- A.
A class with private fields only
Popular companies
Prepare company by company
Hiring pattern, syllabus, past questions and mocks for each company.
All companiesPractice by subject
Programming Languages
What is a closure?
A class with private fields only
A closed browser tab
A function together with the variables from the scope where it was created
A way to end a loop
Sign up free to see the answer and a step-by-step explanation.
What is event delegation in the browser?
Handling events for many child elements with one listener on a common parent, using event bubbling
Sending events to the server
Disabling events
Running events in a worker
Sign up free to see the answer and a step-by-step explanation.
Which value is NOT falsy in JavaScript?
"0"
""
0
null
Sign up free to see the answer and a step-by-step explanation.
What does Array.prototype.map return?
The original array, changed
undefined
The number of elements
A new array with the callback's result for each element
Sign up free to see the answer and a step-by-step explanation.
What is the output of this program?
const out = [];
for (var i = 0; i < 3; i++) {
setTimeout(() => { out.push(i); if (out.length === 3) console.log(out.join(' ')); }, 0);
}
Error
undefined
Sign up free to see the answer and a step-by-step explanation.
What is the output of this program?
const out = [];
for (let i = 0; i < 3; i++) {
setTimeout(() => { out.push(i); if (out.length === 3) console.log(out.join(' ')); }, 0);
}
3 3 3
0 1 2
Sign up free to see the answer and a step-by-step explanation.
What is the output of this program?
console.log('A');
Promise.resolve().then(() => console.log('B'));
console.log('C');
B A C
C A B
Sign up free to see the answer and a step-by-step explanation.
What is the output of this program?
function counter() {
let count = 0;
return () => ++count;
}
const next = counter();
console.log(next(), next());
Error
2 2
Sign up free to see the answer and a step-by-step explanation.
What is the output of this program?
console.log(typeof null);
undefined
null
object
number
Sign up free to see the answer and a step-by-step explanation.
What is the output of this program?
console.log(0.1 + 0.2 === 0.3);
Error
false
Sign up free to see the answer and a step-by-step explanation.
0 1 2
3 3 3
undefined
Error
A C B
A B C
1 1
1 2
undefined
true