Web TippsUse custom web fonts in Google Sheets charts(08.09.2026 um 17:05 Uhr)
Web TippsIntroducing the new 1Password App for Google Chat(08.09.2026 um 18:02 Uhr)
Web TippsUse custom web fonts in Google Sheets charts(08.09.2026 um 17:05 Uhr)
Web TippsIntroducing the new 1Password App for Google Chat(08.09.2026 um 18:02 Uhr)

🔧 Programmierung 🕛 vor 1 Monat 12 Min Lesezeit
0

Can You Guess These 50 JavaScript Outputs? (React Native Interview Edition)

↗ Quelle (dev.to)
🗣️ Stimme:
📑 Inhaltsübersicht




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)




  1. Read the snippet.

  2. Pick A / B / C / D before you scroll.

  3. Open 👀 Reveal answer only after you commit.

  4. 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?





CODE
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?






CODE
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?






CODE
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?






CODE
console.log(add(2, 3));
function add(a, b) {
return a + b;
}






A. 5


B. undefined


C. TypeError


D. ReferenceError




👀 Reveal answer


A. 5

Function declarations are hoisted with their full body.













⚡ Challenge 5 — Guess the output?






CODE
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?






CODE
console.log(name);
const name = "Amit";






A. "Amit"


B. undefined


C. ReferenceError


D. TypeError




👀 Reveal answer


C. ReferenceError

Same TDZ rules as let.













⚡ Challenge 7 — Guess the output?






CODE
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?






CODE
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




👀 Reveal answer


B. 3 3 3

One shared 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?






CODE
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?






CODE
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




👀 Reveal answer


C. 1 2

The returned function closes over the same count. Think custom hooks / factory helpers.













⚡ Challenge 11 — Guess the output?






CODE
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




👀 Reveal answer


A. 1 2 1

Each factory call gets its own lexical environment.













⚡ Challenge 12 — Guess the output?






CODE
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?






CODE
const user = {
name: "Amit",
getName() {
return this.name;
},
};
console.log(user.getName());






A. "Amit"


B. undefined


C. window.name


D. Error




👀 Reveal answer


A. "Amit"

Call site is user.getName()this is user.













⚡ Challenge 14 — Guess the output?






CODE
"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




👀 Reveal answer


C. TypeError

Detached method → this === undefined in strict mode → reading .name throws.


Same pitfall as passing obj.method into a callback without binding.













⚡ Challenge 15 — Guess the output?






CODE
const user = {
name: "Amit",
getName: () => this.name,
};
console.log(user.getName());






A. "Amit"


B. undefined


C. TypeError


D. Always "global"




👀 Reveal answer


B. undefined (typical module / RN runtime)

Arrows do not take this from the object. They capture outer this.













⚡ Challenge 16 — Guess the output?






CODE
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?






CODE
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?






CODE
console.log(null == undefined, null === undefined);






A. true true


B. true false


C. false true


D. false false




👀 Reveal answer


B. true false

Special == rule: null and undefined are loosely equal.













⚡ Challenge 19 — Guess the output?






CODE
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?






CODE
console.log(typeof null, typeof []);






A. "null" "array"


B. "object" "object"


C. "undefined" "object"


D. "null" "object"




👀 Reveal answer


B. "object" "object"

Historic quirk. Use Array.isArray() for arrays.













📦 References (React state landmines)






⚡ Challenge 21 — Guess the output?






CODE
console.log([] === [], [] == []);






A. true true


B. true false


C. false true


D. false false




👀 Reveal answer


D. false false

Each [] is a new object. References never match.













⚡ Challenge 22 — Guess the output?






CODE
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?






CODE
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




👀 Reveal answer


B. "Pune"

Spread is shallow. Nested profile is still shared — classic “I updated state but nested object mutated” interview moment.













⚡ Challenge 24 — Guess the output?






CODE
const obj = {};
const a = {};
const b = {};
obj[a] = "first";
obj[b] = "second";
console.log(obj[a]);






A. "first"


B. "second"


C. undefined


D. Error




👀 Reveal answer


B. "second"

Object keys become strings → both are "[object Object]". Use Map for object identity keys.













📚 Arrays & helpers interviewers love






⚡ Challenge 25 — Guess the output?






CODE
console.log([1, 30, 4, 21].sort());






A. [1, 4, 21, 30]


B. [1, 21, 30, 4]


C. [30, 21, 4, 1]


D. Error




👀 Reveal answer


B. [1, 21, 30, 4]

Default sort compares as strings. Use (a, b) => a - b for numbers.













⚡ Challenge 26 — Guess the output?






CODE
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?






CODE
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?






CODE
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?






CODE
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?






CODE
const [a = 1, b = 2] = [undefined, null];
console.log(a, b);






A. 1 2


B. undefined null


C. 1 null


D. null 2




👀 Reveal answer


C. 1 null

Defaults apply only for undefined, not null — important when APIs return null.













🧩 Parameters, prototypes, classes






⚡ Challenge 31 — Guess the output?






CODE
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




👀 Reveal answer


B. Guest Guest null

Defaults fire for missing args / undefined, not for null.













⚡ Challenge 32 — Guess the output?






CODE
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




👀 Reveal answer


A. 6

Rest params → real array → reduce.













⚡ Challenge 33 — Guess the output?






CODE
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?






CODE
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?






CODE
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




👀 Reveal answer


B. "dark"

Deleting the own property reveals the inherited one again.













⚡ Challenge 36 — Guess the output?






CODE
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?






CODE
const user = new User();
class User {}






A. A User instance


B. undefined


C. ReferenceError


D. TypeError




👀 Reveal answer


C. ReferenceError

Classes are hoisted into the TDZ — not usable before the declaration line.













⏱️ Promises, async/await & the event loop






⚡ Challenge 38 — Guess the output?






CODE
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




👀 Reveal answer


C. start end promise

Sync first → then microtasks.













⚡ Challenge 39 — Guess the output?






CODE
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




👀 Reveal answer


A. start end promise timer

All microtasks before the next macrotask — even setTimeout(..., 0).


Core RN interview question for loading indicators + API race timing.













⚡ Challenge 40 — Guess the output?






CODE
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




👀 Reveal answer


B. 1 3 2

First wave queues 1 and 3. Nested 2 is appended after 1 runs.













⚡ Challenge 41 — Guess the output?






CODE
async function getValue() {
return 42;
}
console.log(getValue());






A. 42


B. Promise { 42 }


C. undefined


D. Error




👀 Reveal answer


B. Promise { 42 }

Formatting varies by engine, but an async function always returns a Promise.













⚡ Challenge 42 — Guess the output?






CODE
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?






CODE
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?






CODE
Promise.all([
Promise.resolve("ok"),
Promise.reject("failed"),
]).then(console.log).catch(console.log);






A. ["ok", "failed"]


B. "failed"


C. "ok"


D. Nothing




👀 Reveal answer


B. "failed"

One rejection fails the whole Promise.all. Prefer Promise.allSettled when you need every result.













⚡ Challenge 45 — Guess the output?






CODE
Promise.resolve("data")
.finally(() => "cleanup")
.then(console.log);






A. "cleanup"


B. "data"


C. undefined


D. Rejection




👀 Reveal answer


B. "data"

A normal return from finally does not replace the resolved value (throwing would).













⚡ Challenge 46 — Guess the output?






CODE
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?






CODE
const first = { id: 1 };
const second = { id: 1 };
console.log(new Set([first, second]).size);






A. 1


B. 2


C. 0


D. Error




👀 Reveal answer


B. 2

Objects compared by reference, not deep equality — same idea as deduping list items incorrectly.













⚡ Challenge 48 — Guess the output?






CODE
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?






CODE
const user = {};
console.log(user.profile?.address?.city);






A. null


B. undefined


C. ReferenceError


D. TypeError




👀 Reveal answer


B. undefined

Optional chaining stops safely — great for messy API payloads in RN.













⚡ Challenge 50 — Guess the output?






CODE
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; varundefined; 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 🚀

Vollständiger Original-Bericht
Ausführliche Details, Code-Beispiele & Hersteller-Stellungnahme auf dev.to.
↗ Original-Artikel auf dev.to lesen
Wie bewertest du diesen Beitrag?
1 Klick Feedback
Teilen mit Netzwerk & Team:

Community-Analysen & Experten-Meinungen 0

Verfasse deine eigene Analyse, teile Workarounds oder diskutiere diesen Vorfall im Blog.
Noch keine Community-Analyse verfasst. Markiere einen Textabschnitt oder klicke oben auf Eigene Analyse verfassen“!
Community Pulse: Relevanz-Einschätzung
1 Klick Experten-Votum
🔴 Akute Relevanz 0%
🟡 In Evaluierung 0%
🟢 Keine Auswirkung 0%
Spannende Innovation 0%
Verwandte Story-Cluster & Quellen (Vektor-KI)
Port 8095 Engine
3 Quellen
Use custom web fonts in Google Sheets charts
2 Quellen
Introducing the new 1Password App for Google Chat
1 Quelle
Context-aware access controls are available for Gemini Enterprise in the Admin console
Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten Can You Guess These 50 JavaScript Outputs? (React Native Interview Edition)

Thematisch verwandte Begriffe: Guess, These, JavaScript, Outputs · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...