DEV Community

Cover image for React Native Interview Handbook — Part 6 of 10: Output-Based JavaScript Practice
Amit Kumar
Amit Kumar

Posted on

React Native Interview Handbook — Part 6 of 10: Output-Based JavaScript Practice

This is Part 6 of 10, a bonus practice article containing 191 output-based JavaScript interview questions. It includes 111 questions drawn from the React Native Interview Handbook plus 80 additional questions on the JavaScript behavior interviewers commonly test in React Native rounds: hoisting, scope, closures, arrays, objects, functions, coercion, conditions, Promises, and the event loop.

Complete series

This Dev.to series has five core handbook articles plus five focused practice extras. Open the series page to move through the complete reading order:

  1. Part 1: JavaScript — core handbook, questions 1–120
  2. Part 2: React — core handbook, questions 121–220
  3. Part 3: React Native — core handbook, questions 221–420
  4. Part 4: Performance & Architecture — core handbook, questions 421–560
  5. Part 5: Senior & System Design — core handbook, questions 561–719
  6. Part 6: Output-Based JavaScript Practice — bonus practice article
  7. Part 7: Coding Interview Practice — bonus practice article
  8. Part 8: Code Output Challenges — bonus practice article
  9. Part 9: Current React Native Interview Questions — new high-frequency practice article
  10. Part 10: Project & Production Interviews — senior project ownership and real-production practice

How to use this guide

Before opening an answer, state the exact output first. Then explain the rule that causes it: evaluation order, scope, coercion, reference identity, prototype lookup, or microtask scheduling. Run the snippet only after committing to an answer.

Topics covered

  • Hoisting, Temporal Dead Zone, var, let, const, and function declarations
  • Scope, closures, this, arrow functions, call, apply, and bind
  • Arrays, sparse arrays, map, reduce, sort, slice, splice, and mutation
  • Objects, references, shallow copies, prototypes, getters, and property lookup
  • Conditions, truthiness, equality, nullish coalescing, and type coercion
  • Promises, async/await, microtasks, timers, and error recovery
  • React and React Native rendering behavior, state updates, effects, and FlatList

Interview answer checklist

  • State the exact output or thrown error.
  • Identify whether the code is synchronous, a microtask, or a timer task.
  • Explain whether values are primitives, references, or inherited properties.
  • Mention the practical React Native consequence when the snippet involves rendering, effects, or the JavaScript thread.

Output-Based JavaScript Questions

111 reviewed questions.

🟡 Intermediate

1. Array equality compares references?

Answer
Answer: Exact output: false, then true
Why: Each array literal creates a distinct object; b points to the same object as a.

Code example:

console.log([] === []);
const a = [];
const b = a;
console.log(a === b);
Enter fullscreen mode Exit fullscreen mode

2. Arrow function and arguments?

Answer
Answer: Exact output: outer
Why: Arrow functions do not create their own arguments object; they capture the surrounding one.

Code example:

function outer() {
  const arrow = () => console.log(arguments[0]);
  arrow('inner');
}
outer('outer');
Enter fullscreen mode Exit fullscreen mode

3. Async function return value?

Answer
Answer: Exact output: true, then 42
Why: An async function always returns a Promise fulfilled with its returned value.

Code example:

async function getValue() {
  return 42;
}
console.log(getValue() instanceof Promise);
getValue().then(console.log);
Enter fullscreen mode Exit fullscreen mode

4. Basic var hoisting?

Answer
Answer: Exact output: undefined, then 10
Why: The declaration is hoisted and initialized with undefined; the assignment stays in place.

Code example:

console.log(a);
var a = 10;
console.log(a);
Enter fullscreen mode Exit fullscreen mode

5. Boolean arithmetic?

Answer
Answer: Exact output: 2, 1, 0
Why: Numeric conversion maps true to 1 and false to 0.

Code example:

console.log(true + true);
console.log(true + false);
console.log(Number(false));
Enter fullscreen mode Exit fullscreen mode

6. Chained map and filter order?

Answer
Answer: Exact output: [6, 8]
Why: map first creates [2, 4, 6, 8], then filter keeps values above 4.

Code example:

const result = [1, 2, 3, 4]
  .map((value) => value * 2)
  .filter((value) => value > 4);
console.log(result);
Enter fullscreen mode Exit fullscreen mode

7. Changing key resets state?

Answer
Answer: Exact output: A changed userId resets Profile's local state
Why: Changing the key makes React treat it as a different component instance.

Code example:

<Profile key={userId} userId={userId} />;
Enter fullscreen mode Exit fullscreen mode

8. Class Temporal Dead Zone?

Answer
Answer: Exact output: ReferenceError
Why: Class declarations are not usable before their declaration is evaluated.

Code example:

const user = new User();
class User {}
Enter fullscreen mode Exit fullscreen mode

9. Closure counter?

Answer
Answer: Exact output: 1, 2
Why: The returned function retains access to its lexical environment.

Code example:

function counter() {
  let count = 0;
  return () => ++count;
}
const next = counter();
console.log(next());
console.log(next());
Enter fullscreen mode Exit fullscreen mode

10. Closure with let in a loop?

Answer
Answer: Exact output: 0, 1, 2
Why: let creates a new binding for every iteration.

Code example:

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

11. Closure with var in a loop?

Answer
Answer: Exact output: 3, 3, 3
Why: All callbacks close over the same function-scoped variable.

Code example:

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

12. Default parameter scope?

Answer
Answer: Exact output: ReferenceError
Why: The parameter's own uninitialized binding shadows the outer value in the default-expression scope.

Code example:

let value = 5;
function show(value = value) {
  return value;
}
show();
Enter fullscreen mode Exit fullscreen mode

13. Default sort is lexicographic?

Answer
Answer: Exact output: [1, 10, 2]
Why: Without a comparator, sort compares string representations.

Code example:

const values = [10, 2, 1];
values.sort();
console.log(values);
Enter fullscreen mode Exit fullscreen mode

14. Destructuring defaults and holes?

Answer
Answer: Exact output: 10, null, 30
Why: Defaults apply to undefined or a missing element, but not to null.

Code example:

const [a = 10, b = 20, c = 30] = [undefined, null];
console.log(a, b, c);
Enter fullscreen mode Exit fullscreen mode

15. Destructuring defaults?

Answer
Answer: Exact output: null, 20
Why: A default value is used only when the property is undefined.

Code example:

const { a = 10, b = 20 } = {
  a: null,
  b: undefined,
};
console.log(a, b);
Enter fullscreen mode Exit fullscreen mode

16. Duplicate function declarations?

Answer
Answer: Exact output: 2
Why: In the same scope, the later function declaration replaces the earlier declaration.

Code example:

console.log(getValue());
function getValue() {
  return 1;
}
function getValue() {
  return 2;
}
Enter fullscreen mode Exit fullscreen mode

17. Effect cleanup order?

Answer
Answer: Exact output: For 0 to 1: effect 0, cleanup 0, effect 1
Why: React cleans up the previous effect before running the replacement.

Code example:

useEffect(() => {
  console.log('effect', count);
  return () => console.log('cleanup', count);
}, [count]);
Enter fullscreen mode Exit fullscreen mode

18. Empty array conversions?

Answer
Answer: Exact output: empty string, 0, true
Why: An empty array converts to an empty string, which converts to zero for numeric comparison.

Code example:

console.log(String([]));
console.log(Number([]));
console.log([] == false);
Enter fullscreen mode Exit fullscreen mode

19. Empty dependency stale closure?

Answer
Answer: Exact output: It repeatedly logs the initial count
Why: The effect callback captures count from the first render.

Code example:

useEffect(() => {
  const id = setInterval(() => console.log(count), 1000);
  return () => clearInterval(id);
}, []); // captures the initial count
Enter fullscreen mode Exit fullscreen mode

20. Event loop: Promise vs timer?

Answer
Answer: Exact output: A, D, C, B
Why: Synchronous code runs first, then microtasks, then timer tasks.

Code example:

console.log('A');
setTimeout(() => console.log('B'), 0);
Promise.resolve().then(() => console.log('C'));
console.log('D');
Enter fullscreen mode Exit fullscreen mode

21. FlatList and extraData?

Answer
Answer: Exact output: Rows may not update when only selectedId changes
Why: FlatList behaves like a PureComponent and may skip work when its relevant props remain shallow-equal.

Code example:

<FlatList
  data={items}
  renderItem={({ item }) => (
    <Row item={item} selected={selectedId === item.id} />
  )}
/>;
Enter fullscreen mode Exit fullscreen mode

22. Function closure after return?

Answer
Answer: Exact output: 1, then 2
Why: inner retains the lexical environment of the completed outer call.

Code example:

function outer() {
  let value = 1;
  return function inner() {
    console.log(value++);
  };
}
const next = outer();
next();
next();
Enter fullscreen mode Exit fullscreen mode

23. Function declaration and var assignment?

Answer
Answer: Exact output: function, then number
Why: The function declaration initializes value first; the runtime assignment later replaces it with 10.

Code example:

console.log(typeof value);
var value = 10;
function value() {}
console.log(typeof value);
Enter fullscreen mode Exit fullscreen mode

24. Function declaration hoisting?

Answer
Answer: Exact output: Hello
Why: A function declaration is hoisted together with its function body.

Code example:

sayHello();
function sayHello() {
  console.log('Hello');
}
Enter fullscreen mode Exit fullscreen mode

25. Function expression hoisting?

Answer
Answer: Exact output: TypeError: sayHello is not a function
Why: Only the var declaration is hoisted. Its value is undefined at the call.

Code example:

sayHello();
var sayHello = function () {
  console.log('Hello');
};
Enter fullscreen mode Exit fullscreen mode

26. Function length?

Answer
Answer: Exact output: 3, 1, 0
Why: Function length counts parameters before the first default and excludes the rest parameter.

Code example:

function first(a, b, c) {}
function second(a, b = 2, c) {}
function third(...args) {}
console.log(first.length, second.length, third.length);
Enter fullscreen mode Exit fullscreen mode

27. Functional state updates?

Answer
Answer: Exact output: After one press, count is 3
Why: React applies each updater to the result of the previous queued updater.

Code example:

setCount((c) => c + 1);
setCount((c) => c + 1);
setCount((c) => c + 1);
Enter fullscreen mode Exit fullscreen mode

28. Getter execution?

Answer
Answer: Exact output: getter, then React Native
Why: Reading an accessor property executes its getter function.

Code example:

const user = {
  first: 'React',
  last: 'Native',
  get name() {
    console.log('getter');
    return `${this.first} ${this.last}`;
  },
};
console.log(user.name);
Enter fullscreen mode Exit fullscreen mode

29. Heavy JavaScript work and UI?

Answer
Answer: Exact output: The app can freeze or drop frames until the loop finishes
Why: Heavy synchronous work blocks the JavaScript thread and delays event handling and React updates.

Code example:

const press = () => {
  const result = expensiveSynchronousLoop();
  setResult(result);
};
Enter fullscreen mode Exit fullscreen mode

30. Hoisting with var?

Answer
Answer: Exact output: undefined
Why: The local declaration is hoisted, but the assignment remains in its original place.

Code example:

var x = 21;
function test() {
  console.log(x);
  var x = 20;
}
test();
Enter fullscreen mode Exit fullscreen mode

31. Lazy state initializer?

Answer
Answer: Exact output: Normally initialize prints only on mount
Why: React calls the initializer to create initial state, not on every ordinary re-render.

Code example:

const [value] = useState(() => {
  console.log('initialize');
  return expensiveCalculation();
});
Enter fullscreen mode Exit fullscreen mode

32. Local var shadows outer variable?

Answer
Answer: Exact output: undefined
Why: The local var is hoisted and shadows the outer count throughout the function.

Code example:

var count = 10;
function show() {
  console.log(count);
  var count = 20;
}
show();
Enter fullscreen mode Exit fullscreen mode

33. Logging immediately after setState?

Answer
Answer: Exact output: The first press logs 0
Why: The handler continues using state from the render that created it.

Code example:

const [count, setCount] = useState(0);
const press = () => {
  setCount(1);
  console.log(count);
};
Enter fullscreen mode Exit fullscreen mode

34. Loose vs strict equality?

Answer
Answer: Exact output: true, false, true, false
Why: Loose equality performs type coercion; strict equality requires matching types.

Code example:

console.log(0 == false);
console.log(0 === false);
console.log('' == false);
console.log('' === false);
Enter fullscreen mode Exit fullscreen mode

35. Multiple Promise microtasks?

Answer
Answer: Exact output: start, end, p1, p2
Why: Promise callbacks are queued in registration order after synchronous code.

Code example:

console.log('start');
Promise.resolve().then(() => console.log('p1'));
Promise.resolve().then(() => console.log('p2'));
console.log('end');
Enter fullscreen mode Exit fullscreen mode

36. Mutating React state?

Answer
Answer: Exact output: A re-render may be skipped
Why: The setter receives the same object reference, so React can consider the state unchanged.

Code example:

const [user, setUser] = useState({ name: 'Alex' });
const press = () => {
  user.name = 'Sam';
  setUser(user);
};
Enter fullscreen mode Exit fullscreen mode

37. NaN equality?

Answer
Answer: Exact output: false, true, true
Why: NaN is unequal to every value under ===, including itself.

Code example:

console.log(NaN === NaN);
console.log(Object.is(NaN, NaN));
console.log(Number.isNaN(NaN));
Enter fullscreen mode Exit fullscreen mode

38. Named function expression scope?

Answer
Answer: Exact output: function, then undefined
Why: The expression's name is available inside its own body, not in the surrounding scope.

Code example:

const run = function internal() {
  console.log(typeof internal);
};
run();
console.log(typeof internal);
Enter fullscreen mode Exit fullscreen mode

39. Nested Promise microtasks?

Answer
Answer: Exact output: 1, 2, 3
Why: The inner Promise callback is queued before the next chained reaction becomes runnable.

Code example:

Promise.resolve()
  .then(() => {
    console.log(1);
    Promise.resolve().then(() => console.log(2));
  })
  .then(() => console.log(3));
Enter fullscreen mode Exit fullscreen mode

40. OR vs nullish coalescing?

Answer
Answer: Exact output: 100, 0, 100
Why: || falls back for all falsy values; ?? only for null or undefined.

Code example:

console.log(0 || 100);
console.log(0 ?? 100);
console.log(null ?? 100);
Enter fullscreen mode Exit fullscreen mode

41. Object dependency causes repeated effects?

Answer
Answer: Exact output: fetch runs after every render
Why: A new options object is created on every render.

Code example:

const options = { page: 1 };
useEffect(() => {
  console.log('fetch');
}, [options]);
Enter fullscreen mode Exit fullscreen mode

42. Object keys are coerced to strings?

Answer
Answer: Exact output: second
Why: Both object keys become the same string, '[object Object]'.

Code example:

const store = {};
const first = { id: 1 };
const second = { id: 2 };
store[first] = 'first';
store[second] = 'second';
console.log(store[first]);
Enter fullscreen mode Exit fullscreen mode

43. Object.assign is shallow?

Answer
Answer: Exact output: true
Why: Object.assign copies the nested reference rather than cloning it.

Code example:

const source = { settings: { dark: false } };
const copy = Object.assign({}, source);
copy.settings.dark = true;
console.log(source.settings.dark);
Enter fullscreen mode Exit fullscreen mode

44. Object.freeze is shallow?

Answer
Answer: Exact output: Pune
Why: The outer object is frozen, but the nested address object is not.

Code example:

const user = Object.freeze({
  name: 'Alex',
  address: { city: 'Delhi' },
});
user.address.city = 'Pune';
console.log(user.address.city);
Enter fullscreen mode Exit fullscreen mode

45. Optional chaining?

Answer
Answer: Exact output: undefined, Guest
Why: Optional chaining stops safely at null/undefined; ?? supplies the fallback.

Code example:

const user = null;
console.log(user?.profile?.name);
console.log(user?.profile?.name ?? 'Guest');
Enter fullscreen mode Exit fullscreen mode

46. Parameter and var with the same name?

Answer
Answer: Exact output: 10, then 20
Why: The parameter supplies the initial local value; redeclaring it with var does not reset it.

Code example:

function show(value) {
  console.log(value);
  var value = 20;
  console.log(value);
}
show(10);
Enter fullscreen mode Exit fullscreen mode

47. Promise chain values?

Answer
Answer: Exact output: 2, 4
Why: Each then receives the value returned by the previous callback.

Code example:

Promise.resolve(1)
  .then((v) => v + 1)
  .then((v) => {
    console.log(v);
    return v * 2;
  })
  .then(console.log);
Enter fullscreen mode Exit fullscreen mode

48. Promise error recovery?

Answer
Answer: Exact output: error, recovered
Why: catch handles the rejection and returns a fulfilled value to the next then.

Code example:

Promise.reject('error')
  .catch((value) => {
    console.log(value);
    return 'recovered';
  })
  .then(console.log);
Enter fullscreen mode Exit fullscreen mode

49. Promise executor is synchronous?

Answer
Answer: Exact output: 1, 2, 4, 3
Why: The Promise constructor executes immediately. The then callback is a microtask.

Code example:

console.log(1);
new Promise((resolve) => {
  console.log(2);
  resolve();
}).then(() => console.log(3));
console.log(4);
Enter fullscreen mode Exit fullscreen mode

50. Promise.race?

Answer
Answer: Exact output: fast
Why: race settles with the first input to settle, not the first item in array order.

Code example:

Promise.race([
  new Promise((resolve) => setTimeout(() => resolve('slow'), 20)),
  Promise.resolve('fast'),
]).then(console.log);
Enter fullscreen mode Exit fullscreen mode

51. Prototype property lookup?

Answer
Answer: Exact output: admin, then editor
Why: user has no own role, so lookup follows its prototype reference.

Code example:

const parent = { role: 'admin' };
const user = Object.create(parent);
user.name = 'Alex';
console.log(user.role);
parent.role = 'editor';
console.log(user.role);
Enter fullscreen mode Exit fullscreen mode

52. React.memo and inline object?

Answer
Answer: Exact output: Child can log again whenever Parent renders
Why: The inline style is a new object reference, so shallow prop comparison fails.

Code example:

<View style={style} />;
});
function Parent() {
 return <Child style={{ flex: 1 }} />;
}
Enter fullscreen mode Exit fullscreen mode

53. Ref updates?

Answer
Answer: Exact output: It increases once for each render
Why: A ref persists between renders, but changing current does not cause a render.

Code example:

const renders = useRef(0);
renders.current += 1;
console.log(renders.current);
Enter fullscreen mode Exit fullscreen mode

54. Regular method vs arrow this?

Answer
Answer: Exact output: Alex, then usually undefined
Why: A regular method receives the calling object as this. An arrow captures lexical this.

Code example:

const user = {
  name: 'Alex',
  regular() {
    console.log(this.name);
  },
  arrow: () => console.log(this.name),
};
user.regular();
user.arrow();
Enter fullscreen mode Exit fullscreen mode

55. Render and effect order?

Answer
Answer: Exact output: Production: render, effect
Why: The component renders first; the passive effect runs after commit.

Code example:

<Text>Hello</Text>;
}
Enter fullscreen mode Exit fullscreen mode

56. Repeated direct state updates?

Answer
Answer: Exact output: After one press, count is 1
Why: All calls calculate the next value from count captured by the current render.

Code example:

const [count, setCount] = useState(0);
const press = () => {
  setCount(count + 1);
  setCount(count + 1);
  setCount(count + 1);
};
Enter fullscreen mode Exit fullscreen mode

57. Rest parameters?

Answer
Answer: Exact output: 1, then [2, 3, 4]
Why: The rest parameter collects remaining arguments into a real array.

Code example:

function inspect(first, ...rest) {
  console.log(first);
  console.log(rest);
}
inspect(1, 2, 3, 4);
Enter fullscreen mode Exit fullscreen mode

58. ScrollView vs FlatList output behavior?

Answer
Answer: ScrollView mounts its children eagerly, which is simple and appropriate for bounded content. FlatList virtualizes data-backed rows and is usually the safer baseline when item count or row cost can grow, but it adds tuning and state-preservation considerations. I choose from measured memory, fill rate, interaction cost, and product constraints rather than a fixed item-count rule.

Code example:

<ScrollView>
  {items.map((item) => (
    <Row key={item.id} item={item} />
  ))}
</ScrollView>;
Enter fullscreen mode Exit fullscreen mode

59. Shallow object equality?

Answer
Answer: Exact output: false, false
Why: Both operators compare object identity, and these are separate objects.

Code example:

const a = { value: 1 };
const b = { value: 1 };
console.log(a === b);
console.log(Object.is(a, b));
Enter fullscreen mode Exit fullscreen mode

60. Shallow spread copy?

Answer
Answer: Exact output: Sam
Why: Spread creates a new outer object but shares nested references.

Code example:

const a = { user: { name: 'Alex' } };
const b = { ...a };
b.user.name = 'Sam';
console.log(a.user.name);
Enter fullscreen mode Exit fullscreen mode

61. Shared object reference?

Answer
Answer: Exact output: Sam
Why: a and b contain references to the same object.

Code example:

const a = { name: 'Alex' };
const b = a;
b.name = 'Sam';
console.log(a.name); // 'Sam'
Enter fullscreen mode Exit fullscreen mode

62. Spread creates a shallow array copy?

Answer
Answer: Exact output: 9
Why: The array container is new, but the nested object reference is shared.

Code example:

const first = [{ value: 1 }];
const second = [...first];
second[0].value = 9;
console.log(first[0].value);
Enter fullscreen mode Exit fullscreen mode

63. Strict Mode console output?

Answer
Answer: Exact output: Development may print render twice; production normally once
Why: Strict Mode repeats selected work in development to expose impure rendering and missing cleanup.

Code example:

<Text>Profile</Text>;
}
Enter fullscreen mode Exit fullscreen mode

64. String addition vs numeric subtraction?

Answer
Answer: Exact output: 52, 3, 51
Why: The + operator concatenates when a string is involved; subtraction converts operands to numbers.

Code example:

console.log('5' + 2);
console.log('5' - 2);
console.log(5 + '2' - 1);
Enter fullscreen mode Exit fullscreen mode

65. String plus number coercion?

Answer
Answer: Exact output: 52, 3, 7
Why: + concatenates when one operand is a string; subtraction performs numeric coercion.

Code example:

console.log('5' + 2);
console.log('5' - 2);
console.log(Number('5') + 2);
Enter fullscreen mode Exit fullscreen mode

66. Strings are immutable?

Answer
Answer: Exact output: React
Why: Assigning to a string index does not modify the string value.

Code example:

let text = 'React';
text[0] = 'X';
console.log(text);
Enter fullscreen mode Exit fullscreen mode

67. Temporal Dead Zone?

Answer
Answer: Exact output: ReferenceError
Why: let is hoisted but cannot be accessed before its declaration is initialized.

Code example:

console.log(value);
let value = 10;
Enter fullscreen mode Exit fullscreen mode

68. Throwing inside then?

Answer
Answer: Exact output: data, caught
Why: An exception in a then callback rejects the Promise returned by that then.

Code example:

Promise.resolve('data')
  .then((value) => {
    console.log(value);
    throw new Error('broken');
  })
  .catch(() => console.log('caught'));
Enter fullscreen mode Exit fullscreen mode

69. Timer callback creates a microtask?

Answer
Answer: Exact output: start, end, timer 1, promise, timer 2
Why: After each timer task, JavaScript drains newly queued microtasks before the next timer task.

Code example:

console.log('start');
setTimeout(() => {
  console.log('timer 1');
  Promise.resolve().then(() => console.log('promise'));
}, 0);
setTimeout(() => console.log('timer 2'), 0);
console.log('end');
Enter fullscreen mode Exit fullscreen mode

70. Truthiness of string values?

Answer
Answer: Exact output: true, true, false, true
Why: Every non-empty string and every object is truthy.

Code example:

console.log(Boolean('false'));
console.log(Boolean('0'));
console.log(Boolean(''));
console.log(Boolean([]));
Enter fullscreen mode Exit fullscreen mode

71. What is the output of a closure counter called three times?

Answer
Answer: It prints 1, 2, 3 because every call updates the same closed-over count. Separate calls to outer create independent closure environments.

Code example:

function outer() {
  let count = 0;
  return () => console.log(++count);
}
const fn = outer();
fn();
fn();
fn(); // 1 2 3
Enter fullscreen mode Exit fullscreen mode

72. What is the output of synchronous logs, Promise.then, and setTimeout(0)?

Answer
Answer: The output is 1, 4, 3, 2: synchronous logs run first, then the Promise microtask, then the timer macrotask. The interview-worthy reasoning is to evaluate operands and side effects in source order, then apply the relevant coercion, scope, or scheduling rule before stating the result.

Code example:

console.log('1');
setTimeout(() => console.log('2'), 0);
Promise.resolve().then(() => console.log('3'));
console.log('4');
// 1 4 3 2
Enter fullscreen mode Exit fullscreen mode

73. What is the output of var versus let in a loop with setTimeout?

Answer
Answer: var produces 3,3,3 because all callbacks share one function-scoped binding after the loop. let produces 0,1,2 because each iteration gets a new binding.

Code example:

for (var i = 0; i < 3; i++) setTimeout(() => console.log(i)); // 3 3 3
for (let i = 0; i < 3; i++) setTimeout(() => console.log(i)); // 0 1 2
Enter fullscreen mode Exit fullscreen mode

74. What is the output when Promise.then and queueMicrotask are queued before a timer?

Answer
Answer: It prints A, E, C, D, B. Synchronous logs run first; Promise.then and queueMicrotask then run in enqueue order; the timer runs afterward.

Code example:

console.log('A');
setTimeout(() => console.log('B'));
Promise.resolve().then(() => console.log('C'));
queueMicrotask(() => console.log('D'));
console.log('E'); // A E C D B
Enter fullscreen mode Exit fullscreen mode

75. What is the output when a property exists only on the prototype?

Answer
Answer: It prints John because property lookup falls through the instance to Person.prototype. The interview-worthy reasoning is to evaluate operands and side effects in source order, then apply the relevant coercion, scope, or scheduling rule before stating the result.

Code example:

function Person() {}
Person.prototype.name = 'John';
const p = new Person();
console.log(p.name); // John
Enter fullscreen mode Exit fullscreen mode

76. What is the result of [] + []?

Answer
Answer: It is an empty string because both arrays convert to empty strings and + performs string concatenation. The interview-worthy reasoning is to evaluate operands and side effects in source order, then apply the relevant coercion, scope, or scheduling rule before stating the result.

Code example:

[] + []; // ''
Enter fullscreen mode Exit fullscreen mode

77. What is the result of [] == false?

Answer
Answer: It is true: the array converts to an empty string and then 0, while false converts to 0. The interview-worthy reasoning is to evaluate operands and side effects in source order, then apply the relevant coercion, scope, or scheduling rule before stating the result.

Code example:

[] == false; // true
Enter fullscreen mode Exit fullscreen mode

78. What is the result of {} + []?

Answer
Answer: The result is parsing-context dependent: leading {} may be parsed as a block, while parenthesized objects convert to '[object Object]'. Never rely on this ambiguity.

Code example:

({}) + []; // '[object Object]'
Enter fullscreen mode Exit fullscreen mode

79. async/await ordering?

Answer
Answer: Exact output: 3, 1, 4, 2
Why: The function runs synchronously until await. Its continuation is a microtask.

Code example:

async function run() {
  console.log(1);
  await Promise.resolve();
  console.log(2);
}
console.log(3);
run();
console.log(4);
Enter fullscreen mode Exit fullscreen mode

80. await with a non-Promise value?

Answer
Answer: Exact output: A, C, B
Why: await behaves like awaiting Promise.resolve(10), so continuation is asynchronous.

Code example:

async function run() {
  console.log('A');
  await 10;
  console.log('B');
}
run();
console.log('C');
Enter fullscreen mode Exit fullscreen mode

81. call, apply and bind?

Answer
Answer: Exact output: Alex-Delhi, Alex-Pune, Alex-Noida
Why: call invokes with separate arguments, apply invokes with an array-like list, and bind returns a function.

Code example:

function intro(city) {
  return `${this.name}-${city}`;
}
const user = { name: 'Alex' };
console.log(intro.call(user, 'Delhi'));
console.log(intro.apply(user, ['Pune']));
console.log(intro.bind(user, 'Noida')());
Enter fullscreen mode Exit fullscreen mode

82. catch recovers a Promise chain?

Answer
Answer: Exact output: failed, recovered
Why: Returning from catch fulfills the next Promise.

Code example:

Promise.reject('failed')
  .catch((error) => {
    console.log(error);
    return 'recovered';
  })
  .then(console.log);
Enter fullscreen mode Exit fullscreen mode

83. const before declaration?

Answer
Answer: Exact output: ReferenceError
Why: const also remains in the Temporal Dead Zone until its declaration executes.

Code example:

console.log(apiUrl);
const apiUrl = 'example.com';
Enter fullscreen mode Exit fullscreen mode

84. const object mutation?

Answer
Answer: Exact output: Sam
Why: const prevents rebinding, not mutation of the referenced object.

Code example:

const user = { name: 'Alex' };
user.name = 'Sam';
console.log(user.name);
Enter fullscreen mode Exit fullscreen mode

85. delete leaves an array hole?

Answer
Answer: Exact output: 3, then false
Why: delete removes the indexed property but does not shift elements or change length.

Code example:

const values = [10, 20, 30];
delete values[1];
console.log(values.length);
console.log(1 in values);
Enter fullscreen mode Exit fullscreen mode

86. delete reveals a prototype value?

Answer
Answer: Exact output: 2, then 1
Why: Deleting the own property exposes the inherited property during the next lookup.

Code example:

const parent = { value: 1 };
const child = Object.create(parent);
child.value = 2;
console.log(child.value);
delete child.value;
console.log(child.value);
Enter fullscreen mode Exit fullscreen mode

87. fill shares object references?

Answer
Answer: Exact output: [5, 5, 5]
Why: fill inserts the same object reference into every position.

Code example:

const rows = Array(3).fill({ count: 0 });
rows[0].count = 5;
console.log(rows.map((row) => row.count));
Enter fullscreen mode Exit fullscreen mode

88. filter(Boolean)?

Answer
Answer: Exact output: [1, 'RN']
Why: Boolean removes all falsy values, not only null and undefined.

Code example:

const values = [0, 1, '', 'RN', null, undefined, false];
console.log(values.filter(Boolean));
Enter fullscreen mode Exit fullscreen mode

89. finally does not replace a value?

Answer
Answer: Exact output: data
Why: A normal return from finally does not replace the settled value.

Code example:

Promise.resolve('data')
  .finally(() => 'other')
  .then(console.log);
Enter fullscreen mode Exit fullscreen mode

90. forEach return value?

Answer
Answer: Exact output: undefined
Why: forEach is for side effects and always returns undefined.

Code example:

const result = [1, 2, 3].forEach((value) => value * 2);
console.log(result);
Enter fullscreen mode Exit fullscreen mode

91. in vs own property?

Answer
Answer: Exact output: true, then false
Why: in checks the prototype chain; Object.hasOwn checks only the object itself.

Code example:

const parent = { role: 'admin' };
const user = Object.create(parent);
user.name = 'Alex';
console.log('role' in user);
console.log(Object.hasOwn(user, 'role'));
Enter fullscreen mode Exit fullscreen mode

92. includes handles NaN?

Answer
Answer: Exact output: -1, true
Why: indexOf uses strict-equality-like comparison; includes uses SameValueZero, which matches NaN.

Code example:

const values = [1, NaN, 3];
console.log(values.indexOf(NaN));
console.log(values.includes(NaN));
Enter fullscreen mode Exit fullscreen mode

93. let before declaration?

Answer
Answer: Exact output: ReferenceError
Why: let is hoisted but remains uninitialized in the Temporal Dead Zone.

Code example:

console.log(a);
let a = 10;
Enter fullscreen mode Exit fullscreen mode

94. let function expression?

Answer
Answer: Exact output: ReferenceError
Why: The let binding exists but is still in the Temporal Dead Zone.

Code example:

greet();
let greet = function () {
  console.log('Hello');
};
Enter fullscreen mode Exit fullscreen mode

95. let is block-scoped?

Answer
Answer: Exact output: ReferenceError
Why: The let binding exists only inside the if block.

Code example:

function test() {
  if (true) {
    let message = 'inside';
  }
  console.log(message);
}
test();
Enter fullscreen mode Exit fullscreen mode

96. map callback without return?

Answer
Answer: Exact output: [undefined, undefined, undefined]
Why: A block-bodied arrow function needs an explicit return.

Code example:

const result = [1, 2, 3].map((value) => {
  value * 2;
});
console.log(result);
Enter fullscreen mode Exit fullscreen mode

97. map with an async callback?

Answer
Answer: Exact output: true
Why: An async callback always returns a Promise, so map creates an array of Promises.

Code example:

const results = [1, 2, 3].map(async (value) => value * 2);
console.log(results[0] instanceof Promise);
Enter fullscreen mode Exit fullscreen mode

98. map with parseInt?

Answer
Answer: Exact output: [1, NaN, NaN]
Why: map supplies value, index and array. parseInt treats the index as its radix.

Code example:

console.log(['1', '2', '3'].map(parseInt));
Enter fullscreen mode Exit fullscreen mode

99. null and undefined arithmetic?

Answer
Answer: Exact output: 1, NaN, 0, NaN
Why: Numeric conversion turns null into 0 and undefined into NaN.

Code example:

console.log(null + 1);
console.log(undefined + 1);
console.log(Number(null));
console.log(Number(undefined));
Enter fullscreen mode Exit fullscreen mode

100. null compared with undefined?

Answer
Answer: Exact output: true, false
Why: Loose equality has a special rule making null equal to undefined; strict equality distinguishes them.

Code example:

console.log(null == undefined);
console.log(null === undefined);
Enter fullscreen mode Exit fullscreen mode

101. push return value?

Answer
Answer: Exact output: 4, then [1, 2, 3, 4]
Why: push mutates the array and returns its new length.

Code example:

const values = [1, 2, 3];
const result = values.push(4);
console.log(result);
console.log(values);
Enter fullscreen mode Exit fullscreen mode

102. reduce without an initial value?

Answer
Answer: Exact output: 6
Why: The first element becomes the initial accumulator and iteration starts at index 1.

Code example:

const values = [1, 2, 3];
const total = values.reduce((sum, value) => sum + value);
console.log(total);
Enter fullscreen mode Exit fullscreen mode

103. replace changes only the first string match?

Answer
Answer: Exact output: RN JS JS, then RN RN RN
Why: A string search in replace affects only the first occurrence; replaceAll affects all.

Code example:

const text = 'JS JS JS';
console.log(text.replace('JS', 'RN'));
console.log(text.replaceAll('JS', 'RN'));
Enter fullscreen mode Exit fullscreen mode

104. slice vs splice?

Answer
Answer: Exact output: [2, 3], [1, 2, 3, 4], [2, 3], [1, 4]
Why: slice returns a non-mutating copy; splice removes/replaces elements in the original.

Code example:

const values = [1, 2, 3, 4];
console.log(values.slice(1, 3));
console.log(values);
console.log(values.splice(1, 2));
console.log(values);
Enter fullscreen mode Exit fullscreen mode

105. slice with negative indexes?

Answer
Answer: Exact output: Script, then JavaScript
Why: slice counts negative indexes from the end; substring treats negative values as zero.

Code example:

const text = 'JavaScript';
console.log(text.slice(-6));
console.log(text.substring(-6));
Enter fullscreen mode Exit fullscreen mode

106. typeof null?

Answer
Answer: Exact output: 'object'
Why: This is a historical JavaScript language quirk.

Code example:

console.log(typeof null); // 'object'
Enter fullscreen mode Exit fullscreen mode

107. useCallback reference stability?

Answer
Answer: Exact output: The function reference stays stable until count changes
Why: useCallback returns the same function while dependencies are equal.

Code example:

const onPress = useCallback(() => {
  console.log(count);
}, [count]);
Enter fullscreen mode Exit fullscreen mode

108. useMemo dependencies?

Answer
Answer: Exact output: calculate runs on mount and when the items reference changes
Why: useMemo reuses its cached value while dependencies remain equal by Object.is.

Code example:

const total = useMemo(() => {
  console.log('calculate');
  return items.reduce((sum, x) => sum + x.price, 0);
}, [items]);
Enter fullscreen mode Exit fullscreen mode

109. var function expression?

Answer
Answer: Exact output: undefined, then TypeError
Why: The variable exists as undefined, but the function assignment has not executed.

Code example:

console.log(typeof greet);
greet();
var greet = function () {
  console.log('Hello');
};
Enter fullscreen mode Exit fullscreen mode

110. var is function-scoped?

Answer
Answer: Exact output: inside
Why: var does not create an if-block scope.

Code example:

function test() {
  if (true) {
    var message = 'inside';
  }
  console.log(message);
}
test();
Enter fullscreen mode Exit fullscreen mode

111. var vs let in loop?

Answer
Answer: Exact output: var prints 3, 3, 3; let prints 0, 1, 2.
Why: var shares one function-scoped binding; let creates a binding per iteration.

Code example:

for (var i = 0; i < 3; i++) setTimeout(() => console.log(i)); // 3 3 3
for (let i = 0; i < 3; i++) setTimeout(() => console.log(i)); // 0 1 2
Enter fullscreen mode Exit fullscreen mode

Extended output-based practice

The following 80 additional questions add deeper practice in the categories most commonly tested in JavaScript and React Native interviews.

Hoisting and scope

🟡 Intermediate

112. var shadows an outer variable?

Answer
Answer: Exact output: undefined

Code example:

var x = 1;
function f() {
  console.log(x);
  var x = 2;
}
f();
Enter fullscreen mode Exit fullscreen mode

113. let before initialization?

Answer
Answer: Exact output: ReferenceError

Code example:

function f() {
  console.log(x);
  let x = 2;
}
f();
Enter fullscreen mode Exit fullscreen mode

114. Function declaration beats var initialization?

Answer
Answer: Exact output: function

Code example:

console.log(typeof f);
var f = 1;
function f() {}
Enter fullscreen mode Exit fullscreen mode

115. Function expression before assignment?

Answer
Answer: Exact output: undefined, then TypeError

Code example:

console.log(typeof f);
f();
var f = () => 1;
Enter fullscreen mode Exit fullscreen mode

116. typeof inside the Temporal Dead Zone?

Answer
Answer: Exact output: ReferenceError

Code example:

{
  console.log(typeof x);
  let x = 1;
}
Enter fullscreen mode Exit fullscreen mode

117. var escapes a block?

Answer
Answer: Exact output: inside

Code example:

if (true) {
  var x = 'inside';
}
console.log(x);
Enter fullscreen mode Exit fullscreen mode

118. let stays inside a block?

Answer
Answer: Exact output: ReferenceError

Code example:

if (true) {
  let x = 'inside';
}
console.log(x);
Enter fullscreen mode Exit fullscreen mode

119. A parameter and var share one binding?

Answer
Answer: Exact output: 1, then 2

Code example:

function f(x) {
  console.log(x);
  var x = 2;
  console.log(x);
}
f(1);
Enter fullscreen mode Exit fullscreen mode

120. A default parameter shadows the outer name?

Answer
Answer: Exact output: ReferenceError

Code example:

let x = 1;
function f(x = x) {
  return x;
}
f();
Enter fullscreen mode Exit fullscreen mode

121. A class is in the Temporal Dead Zone?

Answer
Answer: Exact output: ReferenceError

Code example:

new User();
class User {}
Enter fullscreen mode Exit fullscreen mode

122. const also has a Temporal Dead Zone?

Answer
Answer: Exact output: ReferenceError

Code example:

console.log(x);
const x = 1;
Enter fullscreen mode Exit fullscreen mode

123. A named function expression is local?

Answer
Answer: Exact output: function, then undefined

Code example:

const f = function inner() {
  console.log(typeof inner);
};
f();
console.log(typeof inner);
Enter fullscreen mode Exit fullscreen mode

124. var loop callbacks share one binding?

Answer
Answer: Exact output: 3, 3, 3

Code example:

for (var i = 0; i < 3; i++) setTimeout(() => console.log(i), 0);
Enter fullscreen mode Exit fullscreen mode

125. let loop callbacks have per-iteration bindings?

Answer
Answer: Exact output: 0, 1, 2

Code example:

for (let i = 0; i < 3; i++) setTimeout(() => console.log(i), 0);
Enter fullscreen mode Exit fullscreen mode

126. Assignment before var declaration is local?

Answer
Answer: Exact output: undefined, then local

Code example:

var x = 'outer';
function f() {
  console.log(x);
  x = 'local';
  var x;
}
f();
Enter fullscreen mode Exit fullscreen mode

127. A function declaration is callable early?

Answer
Answer: Exact output: ok

Code example:

f();
function f() {
  console.log('ok');
}
Enter fullscreen mode Exit fullscreen mode

128. A block let can shadow a parameter?

Answer
Answer: Exact output: 2, then 1

Code example:

function f(x) {
  if (true) {
    let x = 2;
    console.log(x);
  }
  console.log(x);
}
f(1);
Enter fullscreen mode Exit fullscreen mode

129. A catch binding is block-scoped?

Answer
Answer: Exact output: caught, then undefined

Code example:

try {
  throw 'caught';
} catch (e) {
  console.log(e);
}
console.log(typeof e);
Enter fullscreen mode Exit fullscreen mode

130. for initializer scope does not leak?

Answer
Answer: Exact output: undefined

Code example:

for (let i = 0; i < 1; i++) {}
console.log(typeof i);
Enter fullscreen mode Exit fullscreen mode

131. A var declaration does not reset a value?

Answer
Answer: Exact output: 5

Code example:

var x = 5;
var x;
console.log(x);
Enter fullscreen mode Exit fullscreen mode

Arrays and conditions

🟡 Intermediate

132. Sparse array map preserves holes?

Answer
Answer: Exact output: 3, false

Code example:

const a = [1, , 3];
const b = a.map((x) => x * 2);
console.log(b.length, 1 in b);
Enter fullscreen mode Exit fullscreen mode

133. Array.fill shares object references?

Answer
Answer: Exact output: [1, 1]

Code example:

const a = Array(2).fill({ n: 0 });
a[0].n = 1;
console.log(a.map((x) => x.n));
Enter fullscreen mode Exit fullscreen mode

134. Default sort is lexicographic?

Answer
Answer: Exact output: [1, 10, 2]

Code example:

console.log([10, 2, 1].sort());
Enter fullscreen mode Exit fullscreen mode

135. slice does not mutate?

Answer
Answer: Exact output: [2, 3], [1, 2, 3]

Code example:

const a = [1, 2, 3];
console.log(a.slice(1), a);
Enter fullscreen mode Exit fullscreen mode

136. splice mutates the source?

Answer
Answer: Exact output: [2], [1, 3]

Code example:

const a = [1, 2, 3];
console.log(a.splice(1, 1), a);
Enter fullscreen mode Exit fullscreen mode

137. delete creates an array hole?

Answer
Answer: Exact output: 3, false

Code example:

const a = [1, 2, 3];
delete a[1];
console.log(a.length, 1 in a);
Enter fullscreen mode Exit fullscreen mode

138. map(parseInt) receives an index radix?

Answer
Answer: Exact output: [1, NaN, NaN]

Code example:

console.log(['1', '2', '3'].map(parseInt));
Enter fullscreen mode Exit fullscreen mode

139. filter(Boolean) removes every falsy value?

Answer
Answer: Exact output: [1, "x"]

Code example:

console.log([0, 1, '', false, 'x', null].filter(Boolean));
Enter fullscreen mode Exit fullscreen mode

140. reduce without an initial value starts at index one?

Answer
Answer: Exact output: 6

Code example:

console.log([1, 2, 3].reduce((a, b) => a + b));
Enter fullscreen mode Exit fullscreen mode

141. forEach returns undefined?

Answer
Answer: Exact output: undefined

Code example:

console.log([1, 2].forEach((x) => x * 2));
Enter fullscreen mode Exit fullscreen mode

142. An array comparison checks references?

Answer
Answer: Exact output: false

Code example:

console.log([1, 2] === [1, 2]);
Enter fullscreen mode Exit fullscreen mode

143. Spread creates a shallow array copy?

Answer
Answer: Exact output: 9

Code example:

const a = [{ n: 1 }],
  b = [...a];
b[0].n = 9;
console.log(a[0].n);
Enter fullscreen mode Exit fullscreen mode

144. includes can match NaN?

Answer
Answer: Exact output: -1, true

Code example:

const a = [NaN];
console.log(a.indexOf(NaN), a.includes(NaN));
Enter fullscreen mode Exit fullscreen mode

145. Empty arrays are truthy?

Answer
Answer: Exact output: true

Code example:

console.log(Boolean([]));
Enter fullscreen mode Exit fullscreen mode

146. An empty array loosely equals false?

Answer
Answer: Exact output: true

Code example:

console.log([] == false);
Enter fullscreen mode Exit fullscreen mode

147. || and ?? treat zero differently?

Answer
Answer: Exact output: 10, 0

Code example:

console.log(0 || 10, 0 ?? 10);
Enter fullscreen mode Exit fullscreen mode

148. Ternary checks truthiness?

Answer
Answer: Exact output: no

Code example:

console.log([] ? 'yes' : 'no');
Enter fullscreen mode Exit fullscreen mode

149. Array destructuring defaults skip only undefined?

Answer
Answer: Exact output: 1, null

Code example:

const [a = 1, b = 2] = [undefined, null];
console.log(a, b);
Enter fullscreen mode Exit fullscreen mode

150. push returns a length?

Answer
Answer: Exact output: 3, [1, 2, 3]

Code example:

const a = [1, 2];
console.log(a.push(3), a);
Enter fullscreen mode Exit fullscreen mode

151. flat removes requested nesting?

Answer
Answer: Exact output: [1, 2, [3]]

Code example:

console.log([1, [2, [3]]].flat(1));
Enter fullscreen mode Exit fullscreen mode

Objects and references

🟡 Intermediate

152. Two object literals are different references?

Answer
Answer: Exact output: false

Code example:

console.log({ a: 1 } === { a: 1 });
Enter fullscreen mode Exit fullscreen mode

153. Assignment shares an object reference?

Answer
Answer: Exact output: Sam

Code example:

const a = { n: 'Alex' },
  b = a;
b.n = 'Sam';
console.log(a.n);
Enter fullscreen mode Exit fullscreen mode

154. Object spread is shallow?

Answer
Answer: Exact output: true

Code example:

const a = { x: { n: 1 } },
  b = { ...a };
b.x.n = 2;
console.log(a.x.n === 2);
Enter fullscreen mode Exit fullscreen mode

155. Object.assign is shallow?

Answer
Answer: Exact output: 2

Code example:

const a = { x: { n: 1 } },
  b = Object.assign({}, a);
b.x.n = 2;
console.log(a.x.n);
Enter fullscreen mode Exit fullscreen mode

156. Object.freeze is shallow?

Answer
Answer: Exact output: 2

Code example:

const a = Object.freeze({ x: { n: 1 } });
a.x.n = 2;
console.log(a.x.n);
Enter fullscreen mode Exit fullscreen mode

157. Object keys coerce to strings?

Answer
Answer: Exact output: second

Code example:

const o = {},
  a = {},
  b = {};
o[a] = 'first';
o[b] = 'second';
console.log(o[a]);
Enter fullscreen mode Exit fullscreen mode

158. A prototype supplies a missing property?

Answer
Answer: Exact output: admin

Code example:

const p = { r: 'admin' },
  u = Object.create(p);
console.log(u.r);
Enter fullscreen mode Exit fullscreen mode

159. Deleting an own property reveals a prototype value?

Answer
Answer: Exact output: 2, then 1

Code example:

const p = { x: 1 },
  o = Object.create(p);
o.x = 2;
console.log(o.x);
delete o.x;
console.log(o.x);
Enter fullscreen mode Exit fullscreen mode

160. in includes inherited properties?

Answer
Answer: Exact output: true, false

Code example:

const p = { x: 1 },
  o = Object.create(p);
console.log('x' in o, Object.hasOwn(o, 'x'));
Enter fullscreen mode Exit fullscreen mode

161. A getter runs when read?

Answer
Answer: Exact output: get, then 2

Code example:

const o = {
  get x() {
    console.log('get');
    return 2;
  },
};
console.log(o.x);
Enter fullscreen mode Exit fullscreen mode

162. const prevents rebinding, not mutation?

Answer
Answer: Exact output: 2

Code example:

const o = { x: 1 };
o.x = 2;
console.log(o.x);
Enter fullscreen mode Exit fullscreen mode

163. Nested destructuring reads a reference?

Answer
Answer: Exact output: 2

Code example:

const a = { x: { n: 1 } },
  b = { x: a.x };
b.x.n = 2;
console.log(a.x.n);
Enter fullscreen mode Exit fullscreen mode

164. Computed keys use evaluated values?

Answer
Answer: Exact output: ok

Code example:

const k = 'name',
  o = { [k]: 'ok' };
console.log(o.name);
Enter fullscreen mode Exit fullscreen mode

165. Optional chaining stops on nullish values?

Answer
Answer: Exact output: undefined

Code example:

const o = null;
console.log(o?.x?.y);
Enter fullscreen mode Exit fullscreen mode

166. Nullish coalescing preserves an empty string?

Answer
Answer: Exact output: empty

Code example:

console.log(('' ?? 'fallback') || 'empty');
Enter fullscreen mode Exit fullscreen mode

167. A Map keeps object keys distinct?

Answer
Answer: Exact output: first, second

Code example:

const a = {},
  b = {},
  m = new Map([
    [a, 'first'],
    [b, 'second'],
  ]);
console.log(m.get(a), m.get(b));
Enter fullscreen mode Exit fullscreen mode

168. JSON cloning drops undefined?

Answer
Answer: Exact output: false

Code example:

const a = { x: undefined },
  b = JSON.parse(JSON.stringify(a));
console.log('x' in b);
Enter fullscreen mode Exit fullscreen mode

169. Property lookup sees later prototype changes?

Answer
Answer: Exact output: 2

Code example:

const p = { x: 1 },
  o = Object.create(p);
p.x = 2;
console.log(o.x);
Enter fullscreen mode Exit fullscreen mode

170. Destructuring copies a primitive value?

Answer
Answer: Exact output: 1

Code example:

const o = { x: 1 };
const { x } = o;
o.x = 2;
console.log(x);
Enter fullscreen mode Exit fullscreen mode

171. A symbol key is not returned by Object.keys?

Answer
Answer: Exact output: 0, 1

Code example:

const s = Symbol(),
  o = { [s]: 1 };
console.log(Object.keys(o).length, Reflect.ownKeys(o).length);
Enter fullscreen mode Exit fullscreen mode

Functions, closures, and this

🟡 Intermediate

172. A closure retains its local value?

Answer
Answer: Exact output: 1, 2

Code example:

function f() {
  let n = 0;
  return () => ++n;
}
const g = f();
console.log(g(), g());
Enter fullscreen mode Exit fullscreen mode

173. Separate closures do not share state?

Answer
Answer: Exact output: 1, 1

Code example:

function f() {
  let n = 0;
  return () => ++n;
}
console.log(f()(), f()());
Enter fullscreen mode Exit fullscreen mode

174. An arrow captures outer arguments?

Answer
Answer: Exact output: outer

Code example:

function f() {
  (() => console.log(arguments[0]))('inner');
}
f('outer');
Enter fullscreen mode Exit fullscreen mode

175. A regular method receives the caller as this?

Answer
Answer: Exact output: Alex

Code example:

const o = {
  n: 'Alex',
  f() {
    console.log(this.n);
  },
};
o.f();
Enter fullscreen mode Exit fullscreen mode

176. An extracted regular method loses its receiver?

Answer
Answer: Exact output: undefined in strict mode

Code example:

'use strict';
const o = {
  n: 'Alex',
  f() {
    console.log(this?.n);
  },
};
const f = o.f;
f();
Enter fullscreen mode Exit fullscreen mode

177. bind fixes a receiver?

Answer
Answer: Exact output: Alex

Code example:

function f() {
  console.log(this.n);
}
f.bind({ n: 'Alex' })();
Enter fullscreen mode Exit fullscreen mode

178. call supplies arguments individually?

Answer
Answer: Exact output: Alex-Pune

Code example:

function f(c) {
  console.log(this.n + '-' + c);
}
f.call({ n: 'Alex' }, 'Pune');
Enter fullscreen mode Exit fullscreen mode

179. apply accepts an argument array?

Answer
Answer: Exact output: Alex-Delhi

Code example:

function f(c) {
  console.log(this.n + '-' + c);
}
f.apply({ n: 'Alex' }, ['Delhi']);
Enter fullscreen mode Exit fullscreen mode

180. An arrow cannot be rebound with call?

Answer
Answer: Exact output: outer

Code example:

const n = 'outer';
const f = () => console.log(n);
f.call({ n: 'inner' });
Enter fullscreen mode Exit fullscreen mode

181. A function length stops at the first default?

Answer
Answer: Exact output: 1

Code example:

function f(a, b = 1, c) {}
console.log(f.length);
Enter fullscreen mode Exit fullscreen mode

182. Rest parameters form an array?

Answer
Answer: Exact output: true

Code example:

function f(...x) {
  console.log(Array.isArray(x));
}
f(1, 2);
Enter fullscreen mode Exit fullscreen mode

183. A default parameter is evaluated at call time?

Answer
Answer: Exact output: 2

Code example:

let x = 1;
function f(a = x) {
  console.log(a);
}
x = 2;
f();
Enter fullscreen mode Exit fullscreen mode

184. this in a timer callback is not the object?

Answer
Answer: Exact output: undefined in strict mode

Code example:

'use strict';
const o = {
  x: 1,
  f() {
    setTimeout(function () {
      console.log(this?.x);
    }, 0);
  },
};
o.f();
Enter fullscreen mode Exit fullscreen mode

185. An arrow timer keeps lexical this?

Answer
Answer: Exact output: 1

Code example:

const o = {
  x: 1,
  f() {
    setTimeout(() => console.log(this.x), 0);
  },
};
o.f();
Enter fullscreen mode Exit fullscreen mode

186. once can cache a function result?

Answer
Answer: Exact output: 1, 1

Code example:

let n = 0;
const once = (f) => {
  let d, v;
  return () => (d ? v : ((d = 1), (v = f())));
};
const f = once(() => ++n);
console.log(f(), f());
Enter fullscreen mode Exit fullscreen mode

187. A callback sees the variable, not its old value?

Answer
Answer: Exact output: 2

Code example:

let x = 1;
const f = () => console.log(x);
x = 2;
f();
Enter fullscreen mode Exit fullscreen mode

188. An IIFE creates a private scope?

Answer
Answer: Exact output: 1, undefined

Code example:

const x = (() => {
  let y = 1;
  return y;
})();
console.log(x, typeof y);
Enter fullscreen mode Exit fullscreen mode

189. A constructor call creates a new receiver?

Answer
Answer: Exact output: Alex

Code example:

function User(n) {
  this.n = n;
}
console.log(new User('Alex').n);
Enter fullscreen mode Exit fullscreen mode

190. Returning an object from a constructor replaces this?

Answer
Answer: Exact output: override

Code example:

function F() {
  this.x = 'this';
  return { x: 'override' };
}
console.log(new F().x);
Enter fullscreen mode Exit fullscreen mode

191. A recursive named function expression can call itself?

Answer
Answer: Exact output: 3

Code example:

const f = function inner(n) {
  return n ? 1 + inner(n - 1) : 0;
};
console.log(f(3));
Enter fullscreen mode Exit fullscreen mode

Continue practising

For architecture, native modules, performance, system design, and behavioral preparation, continue with the Complete React Native Interview Handbook 2026 series on Dev.to.

Top comments (0)