Can You Guess These 50 JavaScript Outputs? (React Native Interview Edition)
React Native interviews rarely ask you to recite API docs.
They drop a short snippet and ask:
Guess the output?
Same language. Same traps. Whether the code runs in a browser, Metro, or Hermes — JavaScript rules don’t change.
These 50 challenges cover what interviewers actually probe:
hoisting · scope · closures · this · coercion · references · prototypes · Promises · async/await · event loop
How to play (same as the Instagram / LinkedIn challenges)
- Read the snippet.
- Pick A / B / C / D before you scroll.
- Open 👀 Reveal answer only after you commit.
- Say why out loud — interviewers care about the explanation as much as the letter.
Challenge rule: Do not run the code until you have made your prediction.
React Native note: Timers, Promises, closures, and shared object references show up as real bugs — stale state, double renders, wrong list keys, race conditions. The UI layer does not rewrite the language.
🔥 Warm-up: coercion, scope, and hoisting
⚡ Challenge 1 — Guess the output?
console.log(1 + "2" + 3 - 4);
A. 119
B. 1234
C. 1199
D. NaN
👀 Reveal answer
A. 119
1 + "2" + 3 → "123" (string concat).
"123" - 4 coerces to number → 119.
⚡ Challenge 2 — Guess the output?
console.log(score);
var score = 10;
A. 10
B. undefined
C. ReferenceError
D. null
👀 Reveal answer
B. undefined
var is hoisted and initialized as undefined. Only the assignment stays in place.
⚡ Challenge 3 — Guess the output?
console.log(score);
let score = 10;
A. 10
B. undefined
C. ReferenceError
D. null
👀 Reveal answer
C. ReferenceError
let is in the Temporal Dead Zone until its line runs. Classic RN interview follow-up after Challenge 2.
⚡ Challenge 4 — Guess the output?
console.log(add(2, 3));
function add(a, b) {
return a + b;
}
A. 5
B. undefined
C. TypeError
D. ReferenceError
Function declarations are hoisted with their full body.👀 Reveal answer
A. 5
⚡ Challenge 5 — Guess the output?
console.log(add(2, 3));
var add = function (a, b) {
return a + b;
};
A. 5
B. undefined
C. TypeError
D. ReferenceError
👀 Reveal answer
C. TypeError
add is hoisted as undefined, then you call undefined(...).
⚡ Challenge 6 — Guess the output?
console.log(name);
const name = "Amit";
A. "Amit"
B. undefined
C. ReferenceError
D. TypeError
Same TDZ rules as 👀 Reveal answer
C. ReferenceError
let.
⚡ Challenge 7 — Guess the output?
var a = 1;
if (true) {
var a = 2;
let b = 3;
}
console.log(a, typeof b);
A. 1 "undefined"
B. 2 "undefined"
C. 2 "number"
D. Error
👀 Reveal answer
B. 2 "undefined"
var is function-scoped (rewrites outer a).
b is block-scoped; typeof safely returns "undefined" for an undeclared identifier.
🔁 Closures & loops (stale-timer territory)
⚡ Challenge 8 — Guess the output?
for (var i = 0; i < 3; i++) {
setTimeout(() => console.log(i), 0);
}
A. 0 1 2
B. 3 3 3
C. 0 0 0
D. Error
One shared 👀 Reveal answer
B. 3 3 3
var i. Loop finishes (i === 3) before timers fire.
Same class of bug as firing three API calls from a loop with the wrong index.
⚡ Challenge 9 — Guess the output?
for (let i = 0; i < 3; i++) {
setTimeout(() => console.log(i), 0);
}
A. 0 1 2
B. 3 3 3
C. 0 0 0
D. Error
👀 Reveal answer
A. 0 1 2
let creates a new binding per iteration.
⚡ Challenge 10 — Guess the output?
function makeCounter() {
let count = 0;
return () => ++count;
}
const counter = makeCounter();
console.log(counter(), counter());
A. 1 1
B. 0 1
C. 1 2
D. Error
The returned function closes over the same 👀 Reveal answer
C. 1 2
count. Think custom hooks / factory helpers.
⚡ Challenge 11 — Guess the output?
function createCounter() {
let count = 0;
return () => ++count;
}
const a = createCounter();
const b = createCounter();
console.log(a(), a(), b());
A. 1 2 1
B. 1 2 3
C. 1 1 1
D. 0 1 0
Each factory call gets its own lexical environment.👀 Reveal answer
A. 1 2 1
⚡ Challenge 12 — Guess the output?
let x = 5;
console.log(x++);
console.log(++x);
console.log(x);
A. 5, 6, 6
B. 5, 7, 7
C. 6, 6, 7
D. 6, 7, 7
👀 Reveal answer
B. 5, 7, 7
x++ returns then increments (5, now 6).
++x increments then returns (7).
Final x is 7.
🎯 this binding (methods, bind, arrows)
⚡ Challenge 13 — Guess the output?
const user = {
name: "Amit",
getName() {
return this.name;
},
};
console.log(user.getName());
A. "Amit"
B. undefined
C. window.name
D. Error
Call site is 👀 Reveal answer
A. "Amit"
user.getName() → this is user.
⚡ Challenge 14 — Guess the output?
"use strict";
const user = {
name: "Amit",
getName() {
return this.name;
},
};
const getName = user.getName;
console.log(getName());
A. "Amit"
B. undefined
C. TypeError
D. ReferenceError
Detached method → 👀 Reveal answer
C. TypeError
this === undefined in strict mode → reading .name throws.
Same pitfall as passing obj.method into a callback without binding.
⚡ Challenge 15 — Guess the output?
const user = {
name: "Amit",
getName: () => this.name,
};
console.log(user.getName());
A. "Amit"
B. undefined
C. TypeError
D. Always "global"
Arrows do not take 👀 Reveal answer
B. undefined (typical module / RN runtime)
this from the object. They capture outer this.
⚡ Challenge 16 — Guess the output?
const user = { name: "Amit" };
function greet() {
return `Hi ${this.name}`;
}
const boundGreet = greet.bind(user);
console.log(boundGreet());
A. "Hi Amit"
B. "Hi undefined"
C. Error
D. undefined
👀 Reveal answer
A. "Hi Amit"
bind locks this permanently.
🧪 Equality, types, and weird JS
⚡ Challenge 17 — Guess the output?
console.log([] == false, [] === false);
A. true true
B. true false
C. false true
D. false false
👀 Reveal answer
B. true false
== coerces both sides toward numbers (0 == 0).
=== also checks type → false.
⚡ Challenge 18 — Guess the output?
console.log(null == undefined, null === undefined);
A. true true
B. true false
C. false true
D. false false
Special 👀 Reveal answer
B. true false
== rule: null and undefined are loosely equal.
⚡ Challenge 19 — Guess the output?
console.log(NaN === NaN, Object.is(NaN, NaN));
A. true true
B. true false
C. false true
D. false false
👀 Reveal answer
C. false true
NaN !== NaN with ===.
Object.is treats two NaNs as equal — useful when validating parsed numbers from APIs.
⚡ Challenge 20 — Guess the output?
console.log(typeof null, typeof []);
A. "null" "array"
B. "object" "object"
C. "undefined" "object"
D. "null" "object"
Historic quirk. Use 👀 Reveal answer
B. "object" "object"
Array.isArray() for arrays.
📦 References (React state landmines)
⚡ Challenge 21 — Guess the output?
console.log([] === [], [] == []);
A. true true
B. true false
C. false true
D. false false
Each 👀 Reveal answer
D. false false
[] is a new object. References never match.
⚡ Challenge 22 — Guess the output?
const a = [1, 2];
const b = a;
b.push(3);
console.log(a);
A. [1, 2]
B. [1, 2, 3]
C. [3]
D. Error
👀 Reveal answer
B. [1, 2, 3]
a and b point to the same array. Mutating “copy” mutates state if you shared the reference.
⚡ Challenge 23 — Guess the output?
const a = { profile: { city: "Delhi" } };
const b = { ...a };
b.profile.city = "Pune";
console.log(a.profile.city);
A. "Delhi"
B. "Pune"
C. undefined
D. Error
Spread is shallow. Nested 👀 Reveal answer
B. "Pune"
profile is still shared — classic “I updated state but nested object mutated” interview moment.
⚡ Challenge 24 — Guess the output?
const obj = {};
const a = {};
const b = {};
obj[a] = "first";
obj[b] = "second";
console.log(obj[a]);
A. "first"
B. "second"
C. undefined
D. Error
Object keys become strings → both are 👀 Reveal answer
B. "second"
"[object Object]". Use Map for object identity keys.
📚 Arrays & helpers interviewers love
⚡ Challenge 25 — Guess the output?
console.log([1, 30, 4, 21].sort());
A. [1, 4, 21, 30]
B. [1, 21, 30, 4]
C. [30, 21, 4, 1]
D. Error
Default 👀 Reveal answer
B. [1, 21, 30, 4]
sort compares as strings. Use (a, b) => a - b for numbers.
⚡ Challenge 26 — Guess the output?
console.log(["1", "2", "3"].map(parseInt));
A. [1, 2, 3]
B. [1, NaN, NaN]
C. [1, 1, 1]
D. Error
👀 Reveal answer
B. [1, NaN, NaN]
map passes (value, index).
parseInt("2", 1) → NaN (bad radix). Prefer .map(Number) or .map((x) => parseInt(x, 10)).
⚡ Challenge 27 — Guess the output?
const items = [1, , 3];
console.log(items.map((x) => x * 2), items.length);
A. [2, 0, 6] 3
B. [2, undefined, 6] 3
C. [2, empty, 6] 3
D. Error
👀 Reveal answer
C. [2, empty, 6] 3
map skips holes and keeps the hole in the result. Length stays 3.
⚡ Challenge 28 — Guess the output?
console.log([0, 1, false, 2, "", 3, null].filter(Boolean));
A. [0, 1, 2, 3]
B. [1, 2, 3]
C. [false, null]
D. Error
👀 Reveal answer
B. [1, 2, 3]
filter(Boolean) drops all falsy values — including legitimate 0 (e.g. quantity / score).
⚡ Challenge 29 — Guess the output?
const values = [1, 2, 3];
const removed = values.splice(1, 1);
console.log(values, removed);
A. [1,2,3] [2]
B. [1,3] [2]
C. [1,3] [1,2]
D. Error
👀 Reveal answer
B. [1,3] [2]
splice mutates and returns removed items. Prefer immutable updates in React state.
⚡ Challenge 30 — Guess the output?
const [a = 1, b = 2] = [undefined, null];
console.log(a, b);
A. 1 2
B. undefined null
C. 1 null
D. null 2
Defaults apply only for 👀 Reveal answer
C. 1 null
undefined, not null — important when APIs return null.
🧩 Parameters, prototypes, classes
⚡ Challenge 31 — Guess the output?
function greet(name = "Guest") {
return name;
}
console.log(greet(), greet(undefined), greet(null));
A. Guest Guest Guest
B. Guest Guest null
C. undefined undefined null
D. Error
Defaults fire for missing args / 👀 Reveal answer
B. Guest Guest null
undefined, not for null.
⚡ Challenge 32 — Guess the output?
function total(...nums) {
return nums.reduce((sum, n) => sum + n, 0);
}
console.log(total(1, 2, 3));
A. 6
B. [1,2,3]
C. 123
D. Error
Rest params → real array → reduce.👀 Reveal answer
A. 6
⚡ Challenge 33 — Guess the output?
function login(email, password = "secret", remember) {}
console.log(login.length);
A. 3
B. 2
C. 1
D. 0
👀 Reveal answer
C. 1
function.length counts parameters before the first defaulted one.
⚡ Challenge 34 — Guess the output?
const parent = { role: "admin" };
const user = Object.create(parent);
user.name = "Amit";
console.log(user.role, user.hasOwnProperty("role"));
A. "admin" true
B. "admin" false
C. undefined false
D. Error
👀 Reveal answer
B. "admin" false
role comes from the prototype chain, not an own property.
⚡ Challenge 35 — Guess the output?
const parent = { theme: "dark" };
const settings = Object.create(parent);
settings.theme = "light";
delete settings.theme;
console.log(settings.theme);
A. "light"
B. "dark"
C. undefined
D. Error
Deleting the own property reveals the inherited one again.👀 Reveal answer
B. "dark"
⚡ Challenge 36 — Guess the output?
const config = Object.freeze({
api: { timeout: 1000 },
});
config.api.timeout = 2000;
console.log(config.api.timeout);
A. 1000
B. 2000
C. TypeError
D. undefined
👀 Reveal answer
B. 2000
Object.freeze is shallow. Nested objects stay mutable.
⚡ Challenge 37 — Guess the output?
const user = new User();
class User {}
A. A User instance
B. undefined
C. ReferenceError
D. TypeError
Classes are hoisted into the TDZ — not usable before the declaration line.👀 Reveal answer
C. ReferenceError
⏱️ Promises, async/await & the event loop
⚡ Challenge 38 — Guess the output?
console.log("start");
Promise.resolve().then(() => console.log("promise"));
console.log("end");
A. start promise end
B. promise start end
C. start end promise
D. Error
Sync first → then microtasks.👀 Reveal answer
C. start end promise
⚡ Challenge 39 — Guess the output?
console.log("start");
setTimeout(() => console.log("timer"), 0);
Promise.resolve().then(() => console.log("promise"));
console.log("end");
A. start end promise timer
B. start promise end timer
C. start end timer promise
D. timer promise start end
All microtasks before the next macrotask — even 👀 Reveal answer
A. start end promise timer
setTimeout(..., 0).
Core RN interview question for loading indicators + API race timing.
⚡ Challenge 40 — Guess the output?
Promise.resolve().then(() => {
console.log(1);
Promise.resolve().then(() => console.log(2));
});
Promise.resolve().then(() => console.log(3));
A. 1 2 3
B. 1 3 2
C. 3 1 2
D. 1 3
First wave queues 👀 Reveal answer
B. 1 3 2
1 and 3. Nested 2 is appended after 1 runs.
⚡ Challenge 41 — Guess the output?
async function getValue() {
return 42;
}
console.log(getValue());
A. 42
B. Promise { 42 }
C. undefined
D. Error
Formatting varies by engine, but an 👀 Reveal answer
B. Promise { 42 }
async function always returns a Promise.
⚡ Challenge 42 — Guess the output?
async function run() {
console.log("inside");
await 0;
console.log("after await");
}
console.log("before");
run();
console.log("after");
A. before inside after await after
B. before inside after after await
C. before after inside after await
D. Error
👀 Reveal answer
B. before inside after after await
await yields; the continuation runs as a microtask after sync work finishes.
⚡ Challenge 43 — Guess the output?
const slow = new Promise((resolve) => setTimeout(() => resolve("slow"), 10));
const fast = Promise.resolve("fast");
Promise.all([slow, fast]).then(console.log);
A. ["fast", "slow"]
B. ["slow", "fast"]
C. "slowfast"
D. Rejection
👀 Reveal answer
B. ["slow", "fast"]
Promise.all keeps input order, not finish order — useful when joining multiple RN API calls.
⚡ Challenge 44 — Guess the output?
Promise.all([
Promise.resolve("ok"),
Promise.reject("failed"),
]).then(console.log).catch(console.log);
A. ["ok", "failed"]
B. "failed"
C. "ok"
D. Nothing
One rejection fails the whole 👀 Reveal answer
B. "failed"
Promise.all. Prefer Promise.allSettled when you need every result.
⚡ Challenge 45 — Guess the output?
Promise.resolve("data")
.finally(() => "cleanup")
.then(console.log);
A. "cleanup"
B. "data"
C. undefined
D. Rejection
A normal return from 👀 Reveal answer
B. "data"
finally does not replace the resolved value (throwing would).
⚡ Challenge 46 — Guess the output?
async function run() {
[1, 2].forEach(async (n) => {
await Promise.resolve();
console.log(n);
});
console.log("done");
}
run();
A. 1 2 done
B. done 1 2
C. done 2 1
D. Nothing
👀 Reveal answer
B. done 1 2
forEach does not await async callbacks. Use for...of + await for sequential RN work (uploads, chained requests).
🗺️ Sets, Maps, modern operators
⚡ Challenge 47 — Guess the output?
const first = { id: 1 };
const second = { id: 1 };
console.log(new Set([first, second]).size);
A. 1
B. 2
C. 0
D. Error
Objects compared by reference, not deep equality — same idea as deduping list items incorrectly.👀 Reveal answer
B. 2
⚡ Challenge 48 — Guess the output?
const map = new Map();
map.set({}, "value");
console.log(map.get({}));
A. "value"
B. undefined
C. null
D. Error
👀 Reveal answer
B. undefined
get({}) uses a new object key, not the stored one.
⚡ Challenge 49 — Guess the output?
const user = {};
console.log(user.profile?.address?.city);
A. null
B. undefined
C. ReferenceError
D. TypeError
Optional chaining stops safely — great for messy API payloads in RN.👀 Reveal answer
B. undefined
⚡ Challenge 50 — Guess the output?
console.log(0 || 10, 0 ?? 10, "" || "guest", "" ?? "guest");
A. 10 0 "guest" ""
B. 0 0 "" ""
C. 10 10 "guest" "guest"
D. Error
👀 Reveal answer
A. 10 0 "guest" ""
|| falls back on any falsy value.
?? falls back only on null / undefined.
Use ?? when 0 or "" are valid (counts, empty search text).
Fast React Native interview revision
| Topic | Remember |
|---|---|
| Hoisting | Declarations hoist; var → undefined; let / const / class → TDZ |
| Closures | Timers/callbacks keep the variables they closed over |
this |
Call site for regular functions; lexical for arrows |
| Equality | Prefer ===; know null == undefined and NaN
|
| References | Arrays/objects share identity; spread is shallow |
| Event loop | Sync → all microtasks → one macrotask |
| Async |
async returns a Promise; forEach won’t await |
Comment challenge
Drop your score in the comments:
X / 50 — and the one question that still feels unfair 👇
If this helped your next React Native / JavaScript interview, bookmark it and practice explaining each answer out loud — that’s what interviewers actually hire for.
Happy coding 🚀
Top comments (0)