Question 61
HardWhat is the output of this program?
console.log([10, , ].(), [, , ].( a - b), [] + {}, [] == );
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?
console.log([10, , ].(), [, , ].( a - b), [] + {}, [] == );
[ 1, 10, 3 ] [ 1, 3, 10 ] [object Object] true
[ 1, 10, 3 ] [ 1, 3, 10 ] {} false
[ 1, 10, 3 ] [ 1, 3, 10 ] [object Object] false
[ 1, 3, 10 ] [ 1, 3, 10 ] [object Object] true
Sign up free to see the answer and a step-by-step explanation.
What is the output of this program?
const obj = {
name: "A",
regular() { return this.name; },
arrow: () => typeof this,
delayed() { return [1].map(() => this.name)[0]; }
};
const f = obj.regular;
console.log(obj.regular(), obj.delayed(), obj.arrow(), typeof f);
A A object undefined
A undefined object function
Sign up free to see the answer and a step-by-step explanation.
What is the output of this program?
const say = (x) => process.stdout.write(x + " ");
async function a() { say(1); await null; say(3); }
say(0);
a();
setTimeout(() => say(5), 0);
Promise.resolve().then(() => say(4));
say(2);
0 2 1 3 4 5
0 1 2 4 3 5
Sign up free to see the answer and a step-by-step explanation.
What is the output of this program?
let a = { x: 1 };
let b = a;
b.x = 2;
b = { x: 3 };
const c = Object.freeze({ y: [1] });
c.y.push(2);
console.log(a.x, b.x, c.y.length);
2 3 1
3 3 1
Sign up free to see the answer and a step-by-step explanation.
What is the output of this program?
function counter() {
let n = 0;
return { inc: () => ++n, get: () => n };
}
const c1 = counter(), c2 = counter();
c1.inc(); c1.inc(); c2.inc();
console.log(c1.get(), c2.get());
2 2
2 1
Sign up free to see the answer and a step-by-step explanation.
What is the output of this program?
console.log(typeof typeof 1, typeof NaN, NaN === NaN, Object.is(NaN, NaN), [NaN].includes(NaN), [NaN].indexOf(NaN));
number number false true true -1
string NaN false true false -1
Sign up free to see the answer and a step-by-step explanation.
What is the output of this program?
const arr = [1, 2, 3, 4];
const [first, , third, ...rest] = arr;
const { a = 10, b: renamed = 20 } = { b: 5 };
console.log(first, third, rest, a, renamed);
1 3 4 undefined 5
1 3 [ 4 ] 10 20
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, (0.1 + 0.2).toFixed(2), 9007199254740993 === 9007199254740992, 2n ** 64n > 2 ** 53);
true 0.30 false true
false 0.30 false true
Sign up free to see the answer and a step-by-step explanation.
What is the output of this program?
var x = 1;
{ var x = 2; }
let y = 1;
{ let y = 2; }
function f() { return typeof z; var z = 5; }
console.log(x, y, f());
2 1 undefined
1 1 undefined
Sign up free to see the answer and a step-by-step explanation.
What is the output of this program?
const p = Promise.all([Promise.resolve(1), 2, new Promise(r => setTimeout(() => r(3), 10))]);
const q = Promise.allSettled([Promise.reject(new Error("x")), Promise.resolve(4)]);
Promise.all([p, q]).then(([a, b]) => console.log(a, b.map(s => s.status)));
[ 1, 2 ] [ 'rejected', 'fulfilled' ]
[ 1, 2, 3 ] [ 'rejected', 'fulfilled' ]
Sign up free to see the answer and a step-by-step explanation.
A A object function
A A undefined function
0 1 3 2 4 5
0 1 2 3 4 5
1 3 2
2 3 2
1 1
3 3
string number true true true 0
string number false true true -1
1 2 [ 3, 4 ] 10 5
1 3 [ 4 ] 10 5
false 0.3 true true
false 0.30 true true
2 1 number
2 2 undefined
Error: x
[ 1, 2, 3 ] [ 'fulfilled', 'fulfilled' ]