Question 31
MediumWhat is the output of this program?
console.log(1);
( .(), );
.();
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(1);
( .(), );
.();
2 1 3
1 2 3
3 1 2
1 3 2
Sign up free to see the answer and a step-by-step explanation.
What is the output of this program?
console.log([1, 2, 3].reduce((acc, x) => acc + x, 0));
[1, 2, 3]
123
Sign up free to see the answer and a step-by-step explanation.
What is the output of this program?
console.log(JSON.stringify([10, 1, 2].sort()));
[2,1,10]
[1,2,10]
Sign up free to see the answer and a step-by-step explanation.
What is the output of this program?
const o = { a: 1, b: 2 };
console.log({ ...o, b: 3, c: 4 });
Error
{ a: 1, b: 2, c: 4 }
Sign up free to see the answer and a step-by-step explanation.
What is the output of this program?
console.log(typeof null, typeof [], typeof undefined, typeof NaN);
object array undefined number
null object undefined number
Sign up free to see the answer and a step-by-step explanation.
What is the output of this program?
console.log([1, 2, 3] + [4], "5" * "2", "5" + 2, 5 + +"2");
[1,2,3,4] 10 7 7
1,2,3,4 10 52 7
Sign up free to see the answer and a step-by-step explanation.
What is the output of this program?
for (var i = 0; i < 3; i++) setTimeout(() => process.stdout.write("v" + i + " "), 0);
for (let j = 0; j < 3; j++) setTimeout(() => process.stdout.write("l" + j + " "), 0);
v3 v3 v3 l0 l1 l2
v0 v1 v2 l0 l1 l2
Sign up free to see the answer and a step-by-step explanation.
What is the output of this program?
console.log("start");
setTimeout(() => console.log("timeout"), 0);
Promise.resolve().then(() => console.log("promise"));
console.log("end");
start promise end timeout
start end promise timeout
Sign up free to see the answer and a step-by-step explanation.
What is the output of this program?
const a = [5, 1, 10, 2];
a.sort();
console.log(a.join(" "));
1 2 5 10
1 10 2 5
Sign up free to see the answer and a step-by-step explanation.
What is the output of this program?
const o = { n: 1, inc() { this.n++; return this; } };
o.inc().inc();
const { n, m = 7 } = o;
console.log(n, m);
2 7
3 7
Sign up free to see the answer and a step-by-step explanation.
0
6
[10,2,1]
[1,10,2]
{ a: 1, b: 3, c: 4 }
{ b: 3, c: 4 }
object object undefined number
null array undefined NaN
1,2,34 52 52 7
1,2,34 10 52 7
l0 l1 l2 v3 v3 v3
v3 v3 v3 l3 l3 l3
start timeout promise end
start end timeout promise
5 1 10 2
10 5 2 1
3 undefined
1 7