Rowdy Coders Logo

Rowdy Coders

Top 50 Most Asked JavaScript Logical/Output Interview Questions

Master the 50 most frequently asked JavaScript logical and output-based interview questions. Practice with interactive code snippets and detailed explanations to ace your next frontend interview.

45 Questions

JavaScript Output Round

Master the trickiest JavaScript concepts through hands-on practice. Predict the output, understand the mechanics, and ace your interviews.

YouTube Video Tutorial

Click to watch video tutorial

1

Guess the output of the following code?

JavaScript
1console.log(5 > '15' < 5);
2console.log(7 < '15' < 7);
3console.log(7 < '85' > 5);
2

Guess the output of the following code?

JavaScript
1console.log(1);
2setTimeout(() => { console.log(2); }, 1000);
3setTimeout(() => { console.log(3); }, 0);
4console.log(4);
3

Guess the output of the following code?

JavaScript
1console.log(1);
2setTimeout(() => { console.log(2); }, 1000);
3setTimeout(() => { console.log(3); }, 0);
4Promise.resolve(1).then(() => {
5 setTimeout(() => { console.log(4); }, 0);
6});
7console.log(5);
4

Guess the output of the following code?

JavaScript
1for (var i = 0; i < 4; i++) {
2 console.log(i);
3}
4for (let i = 0; i < 4; i++) {
5 console.log(i);
6}
5

Guess the output of the following code?

JavaScript
1for (var i = 0; i < 4; i++) {
2 setTimeout(() => { console.log(i); }, 500);
3}
4for (let i = 0; i < 4; i++) {
5 setTimeout(() => { console.log(i); }, 7000);
6}
7for (var i = 0; i < 4; i++) {
8 (function (i) {
9 setTimeout(function () { console.log(i); }, 14000);
10 })(i);
11}
6

Guess the output of the following code?

JavaScript
1console.log(["a"] + ["b"]);
2console.log([] + []);
3console.log(![]);
4console.log(![] + []);
7

Guess the output of the following code?

JavaScript
1console.log(3 < 4 < 5);
2console.log(3 > 4 > 5);
3console.log(3 > 4 > -1);
8

Guess the output of the following code?

JavaScript
1const x1 = new Promise((res) => { setTimeout(res, 500, "one"); });
2const x2 = new Promise((res) => { setTimeout(res, 100, "two"); });
3Promise.all([x1, x2]).then(console.log);
4Promise.race([x1, x2]).then(console.log);
9

Guess the output of the following code?

JavaScript
1const a = {};
2const b = { key: "b" };
3const c = { key: "c" };
4a[b] = 143;
5a[c] = 286;
6console.log(a[b]);
7console.log(b.toString());
10

Guess the output of the following code?

JavaScript
1const h1 = { h: "Thor", i: "IM" };
2const h2 = { h: "Thor", i: "IM" };
3const h3 = h2;
4console.log(h1 == h2);
5console.log(h1 === h2);
6console.log(h2 === h3);
11

Guess the output of the following code?

JavaScript
1const array1 = [1, 2, 3];
2const array2 = [1, 2, 3];
3const array3 = array2;
4console.log(array1 === array2);
5console.log(array2 === array3);
6const User = function(n) { this.name = n; };
7const user1 = new User("Rowdy");
8const user2 = new User("Rowdy");
9console.log(user1 == user2);
12

Guess the output of the following code?

JavaScript
1console.log((1 && 2) || 0 || 3);
2console.log(null && undefined);
3console.log(0 || (1 && 2) || 3);
4console.log(null || (2 && 3) || 4);
13

Guess the output of the following code?

JavaScript
1console.log('goog' > 'bad');
2console.log('Like' < 'like');
3console.log('Subscribe' > 'Subg');
4console.log('SubScribe' > 'Subg');
14

Guess the output of the following code?

JavaScript
1console.log("9" > "11");
2console.log("9" > 11);
3console.log("" > -1);
4console.log("Rowdy" > 1);
15

Guess the output of the following code?

JavaScript
1console.log(Math.round(5.51), Math.round(-5.51));
2console.log(Math.floor(5.51), Math.floor(-5.51));
3console.log(Math.ceil(5.51), Math.ceil(-5.51));
16

Guess the output of the following code?

JavaScript
1function Name() {
2 return
3 { mes: "JavaScript" };
4}
5console.log(Name());
17

Guess the output of the following code?

JavaScript
1var array = [1, 2, 3, 4, 5];
2array.length = 3;
3console.log(array);
4delete array[0];
5console.log(array, array[0]);
18

Guess the output of the following code?

JavaScript
1const arr = [1, 2, 3];
2const str = "1,2,3";
3console.log(arr == str);
19

Guess the output of the following code?

JavaScript
1console.log(3 + 3 + "3" + 3 + 3);
2console.log(1 + 2 + 3 + 4 + 5 + "6");
20

Guess the output of the following code?

JavaScript
1var arr1 = [[1, 2], [2, 4], [4, 8]];
2var arr2 = [...arr1];
3arr1[0][0] = "0";
4arr1[1] = 33;
5console.log(arr2[0][0], arr2[1]);
21

Guess the output of the following code?

JavaScript
1var testArrowFunc = {
2 name: "abc",
3 foo: () => { console.log(this.name); },
4};
5testArrowFunc.foo();
22

Guess the output of the following code?

JavaScript
1console.log(0.1 + 0.2 == 0.3);
2console.log(0.3 + 0.6 == 0.9);
23

Guess the output of the following code?

JavaScript
1console.log("first");
2setTimeout(() => { console.log("second"); });
3queueMicrotask(() => { console.log("third"); });
24

Guess the output of the following code?

JavaScript
1console.log(num);
2var num = 6;
3console.log(num);
25

Guess the output of the following code?

JavaScript
1numb = 6;
2console.log(numb);
3let numb;
26

Guess the output of the following code?

JavaScript
1function* myGenerator() { yield 1; yield 2; }
2const gen = myGenerator();
3console.log(gen.next());
27

Guess the output of the following code?

JavaScript
1console.log(6 + "7");
2console.log(true + 5);
3console.log(true + "5");
28

Guess the output of the following code?

JavaScript
1function exm() {
2 const name = "Rowdy";
3 return function() { return name; };
4}
5const inner = exm();
6console.log(inner());
29

Guess the output of the following code?

JavaScript
1console.log("begins");
2setTimeout(() => {
3 console.log("setTimeout");
4}, 0);
5Promise.resolve().then(() => {
6 console.log("promise");
7});
8console.log("end");
30

Guess the output of the following code?

JavaScript
1async function f() {
2 console.log("start");
3 await Promise.resolve();
4 console.log("end");
5}
6f();
7console.log("sync");
31

Guess the output of the following code?

JavaScript
1process.nextTick(() => console.log('A'));
2Promise.resolve().then(() => console.log('B'));
3setTimeout(() => console.log('C'), 0);
32

Guess the output of the following code?

JavaScript
1const obj = {
2 sing() {
3 console.log("a", this);
4 const inner = function() { console.log("b", this); };
5 inner();
6 }
7};
8obj.sing();
33

Guess the output of the following code?

JavaScript
1let count = 0;
2const b = count++;
3console.log(b, count);
34

Guess the output of the following code?

JavaScript
1let count = 0;
2const b = ++count;
3console.log(b, count);
35

Guess the output of the following code?

JavaScript
1const obj = { age: 1, 1: "a" };
2console.log(Object.keys(obj));
36

Guess the output of the following code?

JavaScript
1(function(x) {
2 return (function(y) {
3 console.log(x);
4 })(2);
5})(1);
37

Guess the output of the following code?

JavaScript
1const obj = { age: 20 };
2Object.freeze(obj);
3obj.age = 30;
4console.log(obj.age);
38

Guess the output of the following code?

JavaScript
1console.log('start');
2setTimeout(() => console.log('timeout'), 0);
3for(let i=0; i<3; i++) console.log('loop');
4console.log('end');
39

Guess the output of the following code?

JavaScript
1function a() {
2 try { return "try"; }
3 finally { return "finally"; }
4}
5console.log(a());
40

Guess the output of the following code?

JavaScript
1let flag = true;
2setTimeout(() => { flag = false; }, 100);
3while(flag) {}
4console.log("done");
41

Guess the output of the following code?

JavaScript
1abc();
2function abc() { console.log("1"); }
3function abc() { console.log("2"); }
42

Guess the output of the following code?

JavaScript
1const p = { name: "A", name: "B" };
2console.log(p.name);
43

Guess the output of the following code?

JavaScript
1const a = {};
2const b = { key: 'b' };
3const c = { key: 'c' };
4a[b] = 123;
5a[c] = 456;
6console.log(a[b]);
44

Guess the output of the following code?

JavaScript
1let v = "Rowdy";
2v[0] = "L";
3console.log(v);
45

Guess the output of the following code?

JavaScript
1console.log(typeof NaN === "number");

Ready for more?

Master Data Structures, Algorithms, and System Design with our curated guides.

Hey Rowdy Coders, In my recent job switch, I have been interviewed at many companies. In this article, I will be sharing all the Top 50 Most Asked JavaScript output-based Interview Questions and Answers.

Why Practice These Questions?#

  1. Fundamental Understanding: These questions test your knowledge of how JavaScript works under the hood.
  2. Speed & Accuracy: In interviews, you often have limited time. Practicing these helps you identify patterns quickly.
  3. Common Pitfalls: Learn about hoisting, closures, event loop, and coercion—the most common areas where developers make mistakes.

Master these to ace your next frontend interview! Rowdy Coders is committed to providing high-signal resources to help you level up your engineering career.