issue 117apr 27mmxxvi
est. 2017
Sun, 27 Apr 2026
vol. IX · no. 117
PapersAdda
placement intelligence, since 2017
640+ briefs · 24 campuses · by reservation
verified offers · sourced from r/developersIndia
razorpay₹65.00 LPA· iit-d · sde-1google₹54.00 LPA· iiit-h · swe-imicrosoft₹49.50 LPA· iit-b · sdeatlassian₹38.00 LPA· nit-w · sde-1amazon₹44.20 LPA· bits-p · sde-1uber₹42.00 LPA· iit-kgp · sde-1razorpay₹65.00 LPA· iit-d · sde-1google₹54.00 LPA· iiit-h · swe-imicrosoft₹49.50 LPA· iit-b · sdeatlassian₹38.00 LPA· nit-w · sde-1amazon₹44.20 LPA· bits-p · sde-1uber₹42.00 LPA· iit-kgp · sde-1

JavaScript Output Questions 2026: 30 Tricky Snippets

9 min read
Interview Questions
Updated: 8 Jun 2026
Aditya Sharma
Aditya's Edit

PapersAdda 2026 Placement Cycle

By Aditya Sharma·Founder & Editor, PapersAdda

What changed in 2026 drives

Mass-recruiter offer letters are flatter for 2026 batch - the 4-5 LPA ASE band has barely budged in three years while inflation eats real wages. Premium tracks (Digital, Pro, Elite, Specialist) are still where the differential lives, and they are entirely test-driven. If you are aiming higher than the default offer, the coding round is not optional pageantry - it is the entire interview.

What I'd actually study for this

  • 01Two solid coding-round answers (1 medium-hard DSA each, with edge-case discussion) > five half-baked ones
  • 02One real project you can defend end-to-end - file paths, design decisions, and what you would change
  • 03One DBMS schema you actually built (not a textbook ER diagram), with at least 3 join-heavy queries written from memory
  • 04Three behavioural STAR stories: failure recovered, conflict handled, ownership taken

Where most candidates trip up

The single biggest mistake is treating company-specific guides as primary prep and DSA as secondary. It is the opposite. Mass recruiters use the test as a filter, but premium tracks at every IT services company use coding to allocate offer band. Spend 70% of prep time on DSA + system fundamentals, 20% on company-specific patterns, 10% on HR rehearsal. Reverse that ratio and you collect the default offer.

Editorial commentary by Aditya Sharma · written for PapersAdda · not generated, not aggregated.

Last Updated: June 2026 | Level: Freshers to Mid-Level | Read Time: ~16 min

JavaScript output questions are the fastest way for interviewers to test real understanding of the language's quirks. Candidates report these dominate frontend and full-stack screens. This guide gives 30 carefully chosen snippets with the exact output and a precise explanation. Every behaviour is verified against the official MDN documentation; confirm any edge case on the ECMAScript reference.

Pair this with JavaScript Interview Questions for Freshers 2026 and JavaScript Closures Interview Questions 2026.


Table of Contents

  1. Hoisting and Scope (Q1 to Q8)
  2. Type Coercion (Q9 to Q16)
  3. this and Closures (Q17 to Q23)
  4. Event Loop and Async (Q24 to Q30)
  5. Quick Trap Table
  6. Frequently Asked Questions

Hoisting and Scope

Q1.

console.log(x);
var x = 5;

Output: undefined Why: var declarations are hoisted and initialised to undefined; only the assignment stays in place. The classic hoisting question.


Q2.

console.log(y);
let y = 5;

Output: ReferenceError Why: let is hoisted but lives in the temporal dead zone until its declaration, so accessing it early throws.


Q3.

function f() {
  console.log(a);
  var a = 1;
  console.log(a);
}
f();

Output:

undefined
1

Why: var a is hoisted to the top of the function; the first log sees undefined, the second sees 1 after assignment.


Q4.

console.log(foo());
function foo() { return "hi"; }

Output: hi Why: Function declarations are fully hoisted, so the call works before the definition line.


Q5.

console.log(bar());
var bar = function() { return "hi"; };

Output: TypeError Why: Only the var bar is hoisted (as undefined); calling undefined throws TypeError. Function expressions are not hoisted like declarations.


Q6.

for (var i = 0; i < 3; i++) {}
console.log(i);

Output: 3 Why: var is function-scoped (here global), so i leaks past the loop with its final value 3.


Q7.

{
  let a = 1;
}
console.log(typeof a);

Output: undefined Why: let is block-scoped, so a does not exist outside the block; typeof on an undeclared name returns "undefined" rather than throwing.


Q8.

var x = 1;
function f() { var x = 2; return x; }
console.log(f(), x);

Output: 2 1 Why: The inner var x shadows the outer; the global x is unchanged.


Type Coercion

Q9.

console.log(1 + "2");
console.log("3" - 1);
console.log("3" * "2");

Output:

12
2
6

Why: + with a string concatenates; - and * coerce strings to numbers.


Q10.

console.log([] + []);
console.log([] + {});
console.log({} + []);

Output:


[object Object]
[object Object]

Why: Arrays and objects coerce to strings via +; an empty array becomes "", an object becomes "[object Object]".


Q11.

console.log(0 == "");
console.log(0 == "0");
console.log("" == "0");

Output:

true
true
false

Why: == coerces: 0 and "" both become 0; "" and "0" are compared as strings and differ. The non-transitivity is the trap.


Q12.

console.log(null == undefined);
console.log(null === undefined);
console.log(null == 0);

Output:

true
false
false

Why: null and undefined are loosely equal only to each other, never to 0.


Q13.

console.log(NaN === NaN);
console.log([NaN].includes(NaN));

Output:

false
true

Why: NaN is not equal to itself under ===, but includes uses SameValueZero which treats NaN as equal.


Q14.

console.log(typeof null);
console.log(typeof NaN);
console.log(typeof []);

Output:

object
number
object

Why: typeof null is a historical bug returning "object"; NaN is a number; arrays report as "object".


Q15.

console.log(true + true);
console.log(!!"");
console.log(!!"0");

Output:

2
false
true

Why: Booleans coerce to numbers (1+1). Empty string is falsy; "0" is a non-empty string and truthy.


Q16.

console.log(0.1 + 0.2 === 0.3);
console.log((0.1 + 0.2).toFixed(2));

Output:

false
0.30

Why: Floating point error makes the sum slightly off; toFixed rounds for display.


this and Closures

Q17.

const obj = {
  name: "A",
  greet() { return this.name; }
};
const g = obj.greet;
console.log(obj.greet(), g());

Output:

A undefined

Why: this depends on the call site. obj.greet() binds this to obj; the detached g() loses that binding (undefined in strict mode or the global object otherwise).


Q18.

const obj = {
  name: "A",
  greet: () => this.name
};
console.log(obj.greet());

Output: undefined Why: Arrow functions do not bind their own this; it comes from the enclosing scope, not obj. Never use an arrow for an object method that needs this.


Q19.

for (var i = 0; i < 3; i++) {
  setTimeout(() => console.log(i), 0);
}

Output:

3
3
3

Why: var is shared, and the callbacks run after the loop, all seeing the final i of 3. Use let for per-iteration scope.


Q20.

for (let i = 0; i < 3; i++) {
  setTimeout(() => console.log(i), 0);
}

Output:

0
1
2

Why: let creates a fresh binding each iteration, so each closure captures its own i.


Q21.

function counter() {
  let c = 0;
  return () => ++c;
}
const inc = counter();
console.log(inc(), inc(), inc());

Output: 1 2 3 Why: The returned closure keeps the private c alive across calls.


Q22.

const a = { x: 1 };
const b = a;
b.x = 2;
console.log(a.x);

Output: 2 Why: Objects are assigned by reference; a and b point to the same object.


Q23.

function f() { return this; }
console.log(typeof f());

Output: object (non-strict) or undefined (strict) Why: A plain function call binds this to the global object in non-strict mode, or undefined in strict mode.


Event Loop and Async

Q24.

console.log(1);
setTimeout(() => console.log(2), 0);
Promise.resolve().then(() => console.log(3));
console.log(4);

Output:

1
4
3
2

Why: Synchronous code first (1, 4), then microtasks (promise, 3), then macrotasks (setTimeout, 2). The microtask-before-macrotask rule is the key.


Q25.

async function f() {
  console.log("a");
  await null;
  console.log("b");
}
console.log("start");
f();
console.log("end");

Output:

start
a
end
b

Why: Code up to the first await runs synchronously; the rest is queued as a microtask after the current stack clears.


Q26.

Promise.resolve()
  .then(() => console.log(1))
  .then(() => console.log(2));
Promise.resolve().then(() => console.log(3));

Output:

1
3
2

Why: Microtasks run in FIFO order across chains; the second .then of the first chain is queued only after its first resolves, by which time chain two's handler has already run.


Q27.

setTimeout(() => console.log("timeout"), 0);
Promise.resolve().then(() => console.log("promise"));
console.log("sync");

Output:

sync
promise
timeout

Why: Same ordering rule: sync, then microtask, then macrotask.


Q28.

async function f() { return 1; }
console.log(f());
f().then(v => console.log(v));

Output:

Promise { 1 }
1

Why: An async function always returns a promise; the value is unwrapped only via then or await.


Q29.

try {
  Promise.reject("err");
} catch (e) {
  console.log("caught");
}
console.log("after");

Output:

after

Why: A rejected promise is not caught by a synchronous try/catch; you need .catch or await inside try. This is a frequent real-world bug.


Q30.

console.log([1, 2, 3].map(n => n * 2));
console.log([1, 2, 3].reduce((a, b) => a + b, 0));

Output:

[ 2, 4, 6 ]
6

Why: map transforms each element; reduce folds to a single accumulated value.


Quick Trap Table

TrapRule to remember
var hoistingdeclared undefined, assignment stays
let TDZreference error before declaration
arrow thisinherits enclosing scope
detached methodloses this binding
var in loop + setTimeoutshares one binding
== coercionnot transitive
typeof null"object" (historical bug)
event loopsync, then microtask, then macrotask
async returnalways a promise

Frequently Asked Questions

Are output prediction questions common in JavaScript interviews in 2026?

Yes. Candidates report that frontend and full-stack screens lean heavily on output prediction for hoisting, type coercion, closures, the this keyword, and the event-loop ordering of setTimeout versus promises.

What is the most common JavaScript output trap?

The event-loop ordering trap: synchronous code runs first, then microtasks (promises), then macrotasks (setTimeout). Predicting the print order of mixed code catches the most candidates.

How do I get fast at JavaScript output prediction?

Internalise hoisting of var and functions, the coercion rules for == and +, closure capture, how this is bound, and the microtask versus macrotask queue. Trace each line in execution order.

Why does an arrow function break object methods?

An arrow function does not bind its own this; it inherits this from the enclosing scope, which is usually not the object. Use a regular method (shorthand or function) when the method needs this.

Why does var leak from a loop but let does not?

var is function-scoped, so one binding is shared across all iterations and survives after the loop. let is block-scoped and creates a fresh binding each iteration.



Every output above is verified against the official MDN documentation. Confirm any edge case on the ECMAScript reference. This guide reflects candidate-reported patterns and public preparation resources as of June 2026.

Methodology applied to this articlelast verified 8 Jun 2026
Sources used
Public exam-pattern documents, official recruiter pages, and verified candidate reports on r/developersIndia and LinkedIn.
Verification window
Page last edited 8 Jun 2026 by Aditya Sharma. Numbers and patterns sanity-checked against the most recent 2026 cycle drives we tracked.
What we did NOT do
  • No fabricated salary numbers or success rates. If we quote a range, it's sourced.
  • No noun-substituted templates. This article was not generated by swapping company names in a stock prompt.
  • No paid placements, sponsored coaching links, or affiliate-shilled course pushes.
Verification policy: /editorial-standards/. Found something incorrect? Submit a correction - we respond within 48 hours.

Explore this topic cluster

More resources in Interview Questions

Use the category hub to browse similar questions, exam patterns, salary guides, and preparation resources related to this topic.

Paid contributor programme

Sat this this year? Share your story, earn ₹500.

First-person experience reports help future candidates prep smarter. We pay verified contributors ₹500 via UPI per accepted story - with byline.

Submit your story →

Ready to practice?

Take a free timed mock test

Put what you learned into practice. Our mock tests match the 2026 pattern with timer, navigator, reveal, and score breakdown. No signup.

Start Free Mock Test →

Related Articles

More from PapersAdda

Share this guide: