Dev.to WebDev 🛠 Dev 👁 0 📖 22 min read

JavaScript Guess the Output Challenges

This standalone challenge set follows the interview-card format: read the code, choose A–D, then open the explanation only after committing to an answer. Challenge rules Predict the exact output, error, or e

This standalone challenge set follows the interview-card format: read the code, choose A–D, then open the explanation only after committing to an answer.

Challenge rules

  • Predict the exact output, error, or execution order.
  • Do not run the snippet before choosing an option.
  • Explain the language rule, not only the final answer.
  • For React Native interviews, connect event-loop and reference questions to UI rendering and JavaScript-thread behavior.

Guess the output

Challenge 1. String coercion chain

Guess the output before revealing the answer.

console.log(1 + '2' + 3 - 4);
Option Output
A 119
B 1234
C 1199
D NaN

Answer and explanation
Correct answer: A

Why: 1 + "2" + 3 becomes the string "123", then subtraction converts it to the number 123; 123 - 4 is 119.


Challenge 2. var before assignment

Guess the output before revealing the answer.

console.log(value);
var value = 10;
Option Output
A 10
B undefined
C ReferenceError
D null

Answer and explanation
Correct answer: B

Why: var is initialized as undefined before its assignment executes.


Challenge 3. let in the Temporal Dead Zone

Guess the output before revealing the answer.

console.log(value);
let value = 10;
Option Output
A 10
B undefined
C ReferenceError
D null

Answer and explanation
Correct answer: C

Why: A lexical binding exists but cannot be read before initialization.


Challenge 4. Function declaration hoisting

Guess the output before revealing the answer.

console.log(add(2, 3));

function add(a, b) {
  return a + b;
}
Option Output
A 5
B undefined
C TypeError
D ReferenceError

Answer and explanation
Correct answer: A

Why: Function declarations are callable before their source line.


Challenge 5. Function expression timing

Guess the output before revealing the answer.

console.log(typeof add);

var add = (a, b) => a + b;
Option Output
A function
B undefined
C object
D ReferenceError

Answer and explanation
Correct answer: B

Why: The var binding is hoisted as undefined; the arrow function is assigned later.


Challenge 6. Array identity

Guess the output before revealing the answer.

console.log([1, 2] === [1, 2]);
Option Output
A true
B false
C undefined
D TypeError

Answer and explanation
Correct answer: B

Why: Each array literal creates a distinct object reference.


Challenge 7. Loose array equality

Guess the output before revealing the answer.

console.log([] == false);
Option Output
A true
B false
C undefined
D TypeError

Answer and explanation
Correct answer: A

Why: The empty array and false both coerce to numeric zero in this loose comparison.


Challenge 8. Strict array equality

Guess the output before revealing the answer.

console.log([] === false);
Option Output
A true
B false
C undefined
D TypeError

Answer and explanation
Correct answer: B

Why: Strict equality does not coerce types.


Challenge 9. Default sort

Guess the output before revealing the answer.

console.log([10, 2, 1].sort());
Option Output
A [1, 2, 10]
B [10, 2, 1]
C [1, 10, 2]
D TypeError

Answer and explanation
Correct answer: C

Why: Default array sort compares string representations.


Challenge 10. map(parseInt)

Guess the output before revealing the answer.

console.log(['1', '2', '3'].map(parseInt));
Option Output
A [1, 2, 3]
B [1, NaN, NaN]
C [NaN, NaN, NaN]
D TypeError

Answer and explanation
Correct answer: B

Why: map passes index as the second argument, which parseInt treats as radix.


Challenge 11. Shared object references

Guess the output before revealing the answer.

const rows = Array(2).fill({ count: 0 });
rows[0].count = 5;
console.log(rows[1].count);
Option Output
A 0
B 1
C 5
D undefined

Answer and explanation
Correct answer: C

Why: fill repeats the same object reference.


Challenge 12. Object key coercion

Guess the output before revealing the answer.

const store = {};
store[{}] = 'first';
store[{}] = 'second';
console.log(store['[object Object]']);
Option Output
A first
B second
C undefined
D TypeError

Answer and explanation
Correct answer: B

Why: Both object keys become the string [object Object].


Challenge 13. Closure counter

Guess the output before revealing the answer.

function makeCounter() {
  let count = 0;
  return () => ++count;
}
const next = makeCounter();
console.log(next(), next());
Option Output
A 0, 1
B 1, 1
C 1, 2
D 2, 2

Answer and explanation
Correct answer: C

Why: The closure retains one mutable count binding.


Challenge 14. Arrow lexical this

Guess the output before revealing the answer.

const user = {
  name: 'Alex',
  show() {
    return (() => this.name)();
  },
};
console.log(user.show());
Option Output
A Alex
B undefined
C ReferenceError
D function

Answer and explanation
Correct answer: A

Why: The arrow captures this from the enclosing regular method.


Challenge 15. Promise versus timer

Guess the output before revealing the answer.

console.log('A');
setTimeout(() => console.log('B'), 0);
Promise.resolve().then(() => console.log('C'));
console.log('D');
Option Output
A A, B, C, D
B A, D, B, C
C A, D, C, B
D A, C, D, B

Answer and explanation
Correct answer: C

Why: Synchronous logs run first, then the Promise microtask, then the timer.


Challenge 16. await continuation

Guess the output before revealing the answer.

async function run() {
  console.log(1);
  await 0;
  console.log(2);
}
run();
console.log(3);
Option Output
A 1, 2, 3
B 1, 3, 2
C 3, 1, 2
D 1, 2, 3

Answer and explanation
Correct answer: B

Why: The async function runs to await, then its continuation is a microtask.


Challenge 17. Nullish coalescing

Guess the output before revealing the answer.

console.log(0 || 10, 0 ?? 10);
Option Output
A 0, 0
B 10, 10
C 10, 0
D 0, 10

Answer and explanation
Correct answer: C

Why: || falls back for falsy values while ?? only falls back for nullish values.


Challenge 18. NaN identity

Guess the output before revealing the answer.

console.log(NaN === NaN, Object.is(NaN, NaN));
Option Output
A true, true
B false, true
C false, false
D true, false

Answer and explanation
Correct answer: B

Why: NaN is not equal to itself with ===; Object.is handles NaN specially.


Challenge 19. Prototype lookup

Guess the output before revealing the answer.

const parent = { role: 'admin' };
const user = Object.create(parent);
console.log(user.role);
Option Output
A admin
B undefined
C null
D ReferenceError

Answer and explanation
Correct answer: A

Why: Property lookup continues through the prototype chain.


Challenge 20. Delete reveals prototype

Guess the output before revealing the answer.

const parent = { value: 1 };
const child = Object.create(parent);
child.value = 2;
delete child.value;
console.log(child.value);
Option Output
A 2
B 1
C undefined
D ReferenceError

Answer and explanation
Correct answer: B

Why: Deleting the own property reveals the inherited value.


Challenge 21. Async map

Guess the output before revealing the answer.

const values = [1, 2].map(async (n) => n * 2);
console.log(values[0] instanceof Promise);
Option Output
A true
B false
C undefined
D TypeError

Answer and explanation
Correct answer: A

Why: An async callback always returns a Promise.


Challenge 22. Promise.all order

Guess the output before revealing the answer.

Promise.all([Promise.resolve('first'), 'second']).then(console.log);
Option Output
A ["second", "first"]
B ["first", "second"]
C first
D second

Answer and explanation
Correct answer: B

Why: Promise.all preserves input order after resolving values.


Challenge 23. Class TDZ

Guess the output before revealing the answer.

console.log(typeof User);
class User {}
Option Output
A function
B undefined
C ReferenceError
D object

Answer and explanation
Correct answer: C

Why: Class declarations have Temporal Dead Zone behavior.


Challenge 24. Private field access

Guess the output before revealing the answer.

class Counter {
  #count = 1;
}
const counter = new Counter();
console.log(counter.#count);
Option Output
A 1
B undefined
C TypeError
D SyntaxError

Answer and explanation
Correct answer: D

Why: Private fields cannot be accessed outside the declaring class body.


Challenge 25. filter(Boolean)

Guess the output before revealing the answer.

console.log([0, 1, '', 'RN', null].filter(Boolean));
Option Output
A [0, 1, "", "RN"]
B [1, "RN"]
C [0, 1, "RN"]
D []

Answer and explanation
Correct answer: B

Why: Boolean removes every falsy item.


Challenge 26. Object freeze depth

Guess the output before revealing the answer.

const user = Object.freeze({ profile: { name: 'Alex' } });
user.profile.name = 'Sam';
console.log(user.profile.name);
Option Output
A Alex
B Sam
C TypeError
D undefined

Answer and explanation
Correct answer: B

Why: Object.freeze is shallow; the nested profile object is still mutable.


Challenge 27. Rest parameters

Guess the output before revealing the answer.

function inspect(first, ...rest) {
  console.log(first, Array.isArray(rest));
}
inspect(1, 2, 3);
Option Output
A 1, true
B 1, false
C [1, 2, 3], true
D undefined, true

Answer and explanation
Correct answer: A

Why: The first argument is separate and the rest parameter is a real array.


Challenge 28. Function length

Guess the output before revealing the answer.

function first(a, b, c) {}
function second(a, b = 2, c) {}
console.log(first.length, second.length);
Option Output
A 3, 3
B 3, 2
C 3, 1
D 2, 1

Answer and explanation
Correct answer: C

Why: Function length counts parameters before the first default.


Challenge 29. Sparse array hole

Guess the output before revealing the answer.

const values = [1, , 3];
console.log(values.length, 1 in values);
Option Output
A 2, false
B 3, false
C 3, true
D 2, true

Answer and explanation
Correct answer: B

Why: The missing element is a hole but still contributes to array length.


Challenge 30. finally value

Guess the output before revealing the answer.

Promise.resolve('data')
  .finally(() => 'other')
  .then(console.log);
Option Output
A data
B other
C undefined
D Promise

Answer and explanation
Correct answer: A

Why: A normal return from finally does not replace the fulfilled value.


Extended 100-question interview challenge bank

Challenges 31–100 cover distinct JavaScript topics that frequently appear in frontend, React, and React Native interviews: coercion, arrays, references, closures, classes, Promises, and the event loop.

Type coercion, equality, and values

Challenge 31. String plus number

Predict the exact output before opening the answer.

console.log('5' + 1);
Option Output
A TypeError
B 51
C undefined
D false

Answer and explanation
Correct answer: B

Why: String concatenation wins when either operand of + is a string.


Challenge 32. String minus number

Predict the exact output before opening the answer.

console.log('5' - 1);
Option Output
A 4
B undefined
C false
D TypeError

Answer and explanation
Correct answer: A

Why: - converts numeric strings to numbers.


Challenge 33. Loose equality with arrays

Predict the exact output before opening the answer.

console.log([] == ![]);
Option Output
A undefined
B false
C TypeError
D true

Answer and explanation
Correct answer: D

Why: ![] is false; the empty array becomes an empty string, which becomes 0 during loose comparison.


Challenge 34. Loose null equality

Predict the exact output before opening the answer.

console.log(null == undefined);
Option Output
A false
B TypeError
C true
D undefined

Answer and explanation
Correct answer: C

Why: The loose-equality algorithm treats null and undefined as equal to each other.


Challenge 35. Strict null equality

Predict the exact output before opening the answer.

console.log(null === undefined);
Option Output
A NaN
B false
C undefined
D TypeError

Answer and explanation
Correct answer: B

Why: Strict equality requires the same type.


Challenge 36. NaN strict equality

Predict the exact output before opening the answer.

console.log(NaN === NaN);
Option Output
A false
B undefined
C TypeError
D NaN

Answer and explanation
Correct answer: A

Why: NaN is the only JavaScript value not equal to itself.


Challenge 37. NaN with Object.is

Predict the exact output before opening the answer.

console.log(Object.is(NaN, NaN));
Option Output
A undefined
B false
C TypeError
D true

Answer and explanation
Correct answer: D

Why: Object.is considers NaN the same value as NaN.


Challenge 38. Signed zero

Predict the exact output before opening the answer.

console.log(Object.is(0, -0));
Option Output
A TypeError
B NaN
C false
D undefined

Answer and explanation
Correct answer: C

Why: Object.is distinguishes positive and negative zero.


Challenge 39. Truthy string

Predict the exact output before opening the answer.

console.log(Boolean('0'));
Option Output
A TypeError
B true
C undefined
D false

Answer and explanation
Correct answer: B

Why: Every non-empty string is truthy, including "0".


Challenge 40. Empty array string conversion

Predict the exact output before opening the answer.

console.log([] + []);
Option Output
A ``
B undefined
C false
D TypeError

{% details Answer and explanation %}
Correct answer: A

Why: Both arrays convert to empty strings before concatenation.
{% enddetails %}

Challenge 41. Array and object conversion

Predict the exact output before opening the answer.

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

Option Output
A undefined
B false
C TypeError
D [object Object]

{% details Answer and explanation %}
Correct answer: D

Why: The array becomes an empty string and the object becomes "[object Object]".
{% enddetails %}

Challenge 42. Numeric boolean addition

Predict the exact output before opening the answer.

`javascript
console.log(true + true);
`

Option Output
A false
B TypeError
C 2
D undefined

{% details Answer and explanation %}
Correct answer: C

Why: In numeric addition, true converts to 1.
{% enddetails %}

Challenge 43. Undefined numeric conversion

Predict the exact output before opening the answer.

`javascript
console.log(undefined + 1);
`

Option Output
A TypeError
B NaN
C undefined
D false

{% details Answer and explanation %}
Correct answer: B

Why: undefined converts to NaN in numeric arithmetic.
{% enddetails %}

Challenge 44. Null numeric conversion

Predict the exact output before opening the answer.

`javascript
console.log(null + 1);
`

Option Output
A 1
B undefined
C false
D TypeError

{% details Answer and explanation %}
Correct answer: A

Why: null converts to 0 in numeric arithmetic.
{% enddetails %}

Arrays and array methods

Challenge 45. map with parseInt

Predict the exact output before opening the answer.

`javascript
console.log([1, 2, 3].map(parseInt));
`

Option Output
A undefined
B false
C TypeError
D [1, NaN, NaN]

{% details Answer and explanation %}
Correct answer: D

Why: map passes value, index, and array; parseInt reads the index as its radix.
{% enddetails %}

Challenge 46. Default array sort

Predict the exact output before opening the answer.

`javascript
console.log([10, 2, 1].sort());
`

Option Output
A false
B TypeError
C [1, 10, 2]
D undefined

{% details Answer and explanation %}
Correct answer: C

Why: Without a comparator, sort compares string representations.
{% enddetails %}

Challenge 47. Numeric array sort

Predict the exact output before opening the answer.

`javascript
console.log([10, 2, 1].sort((a, b) => a - b));
`

Option Output
A TypeError
B [1, 2, 10]
C undefined
D false

{% details Answer and explanation %}
Correct answer: B

Why: The comparator performs numeric ordering.
{% enddetails %}

Challenge 48. reduce total

Predict the exact output before opening the answer.

`javascript
console.log([1, 2, 3].reduce((sum, n) => sum + n, 0));
`

Option Output
A 6
B undefined
C false
D TypeError

{% details Answer and explanation %}
Correct answer: A

Why: reduce accumulates values from the supplied initial value.
{% enddetails %}

Challenge 49. filter Boolean

Predict the exact output before opening the answer.

`javascript
console.log([0, 1, false, 2, ''].filter(Boolean));
`

Option Output
A undefined
B false
C TypeError
D [1, 2]

{% details Answer and explanation %}
Correct answer: D

Why: filter(Boolean) removes falsy values.
{% enddetails %}

Challenge 50. slice does not mutate

Predict the exact output before opening the answer.

`javascript
const a = [1, 2, 3];
a.slice(1);
console.log(a);
`

Option Output
A false
B TypeError
C [1, 2, 3]
D undefined

{% details Answer and explanation %}
Correct answer: C

Why: slice returns a new array and leaves the source unchanged.
{% enddetails %}

Challenge 51. splice mutates

Predict the exact output before opening the answer.

`javascript
const a = [1, 2, 3];
a.splice(1, 1);
console.log(a);
`

Option Output
A TypeError
B [1, 3]
C undefined
D false

{% details Answer and explanation %}
Correct answer: B

Why: splice changes the original array.
{% enddetails %}

Challenge 52. flat default depth

Predict the exact output before opening the answer.

`javascript
console.log([1, [2, [3]]].flat());
`

Option Output
A [1, 2, [3]]
B undefined
C false
D TypeError

{% details Answer and explanation %}
Correct answer: A

Why: flat uses depth 1 by default.
{% enddetails %}

Challenge 53. Negative at index

Predict the exact output before opening the answer.

`javascript
console.log(['a', 'b', 'c'].at(-1));
`

Option Output
A undefined
B false
C TypeError
D c

{% details Answer and explanation %}
Correct answer: D

Why: at supports negative indexes from the end of the array.
{% enddetails %}

Challenge 54. Array.from a string

Predict the exact output before opening the answer.

`javascript
console.log(Array.from('hi'));
`

Option Output
A false
B TypeError
C [h, i]
D undefined

{% details Answer and explanation %}
Correct answer: C

Why: Array.from creates an array from an iterable.
{% enddetails %}

Challenge 55. forEach return value

Predict the exact output before opening the answer.

`javascript
console.log([1, 2].forEach((n) => n * 2));
`

Option Output
A NaN
B undefined
C false
D TypeError

{% details Answer and explanation %}
Correct answer: B

Why: forEach is for side effects and always returns undefined.
{% enddetails %}

Challenge 56. includes NaN

Predict the exact output before opening the answer.

`javascript
console.log([NaN].includes(NaN));
`

Option Output
A true
B undefined
C false
D TypeError

{% details Answer and explanation %}
Correct answer: A

Why: includes uses SameValueZero, which matches NaN.
{% enddetails %}

Challenge 57. indexOf NaN

Predict the exact output before opening the answer.

`javascript
console.log([NaN].indexOf(NaN));
`

Option Output
A undefined
B false
C TypeError
D -1

{% details Answer and explanation %}
Correct answer: D

Why: indexOf uses strict equality, which cannot match NaN.
{% enddetails %}

Challenge 58. fill mutates

Predict the exact output before opening the answer.

`javascript
const a = [1, 2, 3];
a.fill(0, 1);
console.log(a);
`

Option Output
A false
B TypeError
C [1, 0, 0]
D undefined

{% details Answer and explanation %}
Correct answer: C

Why: fill overwrites items in the existing array.
{% enddetails %}

Objects, references, and collections

Challenge 59. Reference comparison

Predict the exact output before opening the answer.

`javascript
console.log({} === {});
`

Option Output
A NaN
B false
C undefined
D TypeError

{% details Answer and explanation %}
Correct answer: B

Why: Each object literal creates a different reference.
{% enddetails %}

Challenge 60. Shared object reference

Predict the exact output before opening the answer.

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

Option Output
A 2
B undefined
C false
D TypeError

{% details Answer and explanation %}
Correct answer: A

Why: Both variables point to the same object.
{% enddetails %}

Challenge 61. Shallow copy nested reference

Predict the exact output before opening the answer.

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

Option Output
A undefined
B false
C TypeError
D 2

{% details Answer and explanation %}
Correct answer: D

Why: Object spread is shallow; nested objects remain shared.
{% enddetails %}

Challenge 62. Spread override order

Predict the exact output before opening the answer.

`javascript
console.log({ x: 1, ...{ x: 2 } }.x);
`

Option Output
A false
B TypeError
C 2
D undefined

{% details Answer and explanation %}
Correct answer: C

Why: Properties added later overwrite earlier properties.
{% enddetails %}

Challenge 63. Object keys order

Predict the exact output before opening the answer.

`javascript
console.log(Object.keys({ 2: 'b', 1: 'a', x: 'c' }));
`

Option Output
A TypeError
B [1, 2, x]
C undefined
D false

{% details Answer and explanation %}
Correct answer: B

Why: Integer-like keys are listed in ascending order before other string keys.
{% enddetails %}

Challenge 64. Inherited property with in

Predict the exact output before opening the answer.

`javascript
const proto = { x: 1 };
const obj = Object.create(proto);
console.log('x' in obj);
`

Option Output
A true
B undefined
C false
D TypeError

{% details Answer and explanation %}
Correct answer: A

Why: in searches an object and its prototype chain.
{% enddetails %}

Challenge 65. Own property check

Predict the exact output before opening the answer.

`javascript
const proto = { x: 1 };
const obj = Object.create(proto);
console.log(Object.hasOwn(obj, 'x'));
`

Option Output
A undefined
B TypeError
C NaN
D false

{% details Answer and explanation %}
Correct answer: D

Why: x is inherited rather than an own property.
{% enddetails %}

Challenge 66. Optional chaining

Predict the exact output before opening the answer.

`javascript
const user = null;
console.log(user?.name);
`

Option Output
A TypeError
B NaN
C undefined
D false

{% details Answer and explanation %}
Correct answer: C

Why: Optional chaining short-circuits on null or undefined.
{% enddetails %}

Challenge 67. Nullish coalescing

Predict the exact output before opening the answer.

`javascript
console.log(0 ?? 10);
`

Option Output
A TypeError
B 0
C undefined
D false

{% details Answer and explanation %}
Correct answer: B

Why: ?? only falls back for null or undefined, not other falsy values.
{% enddetails %}

Challenge 68. Logical OR fallback

Predict the exact output before opening the answer.

`javascript
console.log(0 || 10);
`

Option Output
A 10
B undefined
C false
D TypeError

{% details Answer and explanation %}
Correct answer: A

Why: || falls back for any falsy left operand.
{% enddetails %}

Challenge 69. JSON removes undefined

Predict the exact output before opening the answer.

`javascript
console.log(JSON.stringify({ x: undefined, y: 1 }));
`

Option Output
A undefined
B false
C TypeError
D {"y":1}

{% details Answer and explanation %}
Correct answer: D

Why: JSON.stringify omits object properties whose value is undefined.
{% enddetails %}

Challenge 70. Set object identity

Predict the exact output before opening the answer.

`javascript
console.log(new Set([{}, {}]).size);
`

Option Output
A false
B TypeError
C 2
D undefined

{% details Answer and explanation %}
Correct answer: C

Why: Different object literals have different identities.
{% enddetails %}

Challenge 71. Map object key identity

Predict the exact output before opening the answer.

`javascript
const key = {};
const map = new Map([[key, 'yes']]);
console.log(map.get(key));
`

Option Output
A TypeError
B yes
C undefined
D false

{% details Answer and explanation %}
Correct answer: B

Why: Map can use an object reference as a key.
{% enddetails %}

Challenge 72. Freeze is shallow

Predict the exact output before opening the answer.

`javascript
const obj = Object.freeze({ nested: { x: 1 } });
obj.nested.x = 2;
console.log(obj.nested.x);
`

Option Output
A 2
B undefined
C false
D TypeError

{% details Answer and explanation %}
Correct answer: A

Why: Object.freeze does not recursively freeze nested objects.
{% enddetails %}

Functions, scope, closures, and classes

Challenge 73. Function declaration hoisting

Predict the exact output before opening the answer.

`javascript
console.log(square(2));
function square(n) { return n * n; }
`

Option Output
A undefined
B false
C TypeError
D 4

{% details Answer and explanation %}
Correct answer: D

Why: Function declarations are available before their declaration line.
{% enddetails %}

Challenge 74. var hoisting value

Predict the exact output before opening the answer.

`javascript
console.log(value);
var value = 3;
`

Option Output
A TypeError
B NaN
C undefined
D false

{% details Answer and explanation %}
Correct answer: C

Why: var declarations are hoisted and initialized with undefined.
{% enddetails %}

Challenge 75. Closure retains state

Predict the exact output before opening the answer.

`javascript
function counter() {
let n = 0;
return () => ++n;
}
const next = counter();
console.log(next(), next());
`

Option Output
A TypeError
B 1, 2
C undefined
D false

{% details Answer and explanation %}
Correct answer: B

Why: The closure retains the same n binding between calls.
{% enddetails %}

Challenge 76. let loop binding

Predict the exact output before opening the answer.

`javascript
const fns = [];
for (let i = 0; i < 3; i++) fns.push(() => i);
console.log(fns[2]());
`

Option Output
A 2
B undefined
C false
D TypeError

{% details Answer and explanation %}
Correct answer: A

Why: let creates a fresh loop binding for each iteration.
{% enddetails %}

Challenge 77. var loop binding

Predict the exact output before opening the answer.

`javascript
const fns = [];
for (var i = 0; i < 3; i++) fns.push(() => i);
console.log(fns[0]());
`

Option Output
A undefined
B false
C TypeError
D 3

{% details Answer and explanation %}
Correct answer: D

Why: var has function scope, so each closure sees the final i.
{% enddetails %}

Challenge 78. Default parameter undefined

Predict the exact output before opening the answer.

`javascript
function f(x = 1) { return x; }
console.log(f(undefined));
`

Option Output
A false
B TypeError
C 1
D undefined

{% details Answer and explanation %}
Correct answer: C

Why: A default parameter applies to an undefined argument.
{% enddetails %}

Challenge 79. Default parameter null

Predict the exact output before opening the answer.

`javascript
function f(x = 1) { return x; }
console.log(f(null));
`

Option Output
A TypeError
B null
C undefined
D false

{% details Answer and explanation %}
Correct answer: B

Why: null is an explicit value, so the default does not apply.
{% enddetails %}

Challenge 80. Arrow implicit object return

Predict the exact output before opening the answer.

`javascript
const f = () => ({ x: 1 });
console.log(f().x);
`

Option Output
A 1
B undefined
C false
D TypeError

{% details Answer and explanation %}
Correct answer: A

Why: Parentheses make the object an expression rather than a function body.
{% enddetails %}

Challenge 81. bind preserves this

Predict the exact output before opening the answer.

`javascript
function get() { return this.x; }
const bound = get.bind({ x: 2 });
console.log(bound());
`

Option Output
A undefined
B false
C TypeError
D 2

{% details Answer and explanation %}
Correct answer: D

Why: bind creates a function with a fixed this value.
{% enddetails %}

Challenge 82. call sets this

Predict the exact output before opening the answer.

`javascript
function get() { return this.x; }
console.log(get.call({ x: 3 }));
`

Option Output
A false
B TypeError
C 3
D undefined

{% details Answer and explanation %}
Correct answer: C

Why: call invokes a function with the specified receiver.
{% enddetails %}

Challenge 83. Rest parameter

Predict the exact output before opening the answer.

`javascript
function count(...args) { return args.length; }
console.log(count(1, 2, 3));
`

Option Output
A TypeError
B 3
C undefined
D false

{% details Answer and explanation %}
Correct answer: B

Why: Rest parameters collect remaining arguments into an array.
{% enddetails %}

Challenge 84. Class private field

Predict the exact output before opening the answer.

`javascript
class User {
#name = 'Ada';
getName() { return this.#name; }
}
console.log(new User().getName());
`

Option Output
A Ada
B undefined
C false
D TypeError

{% details Answer and explanation %}
Correct answer: A

Why: A private field is accessible within its class definition.
{% enddetails %}

Challenge 85. Static class method

Predict the exact output before opening the answer.

`javascript
class User { static role() { return 'admin'; } }
console.log(User.role());
`

Option Output
A undefined
B false
C TypeError
D admin

{% details Answer and explanation %}
Correct answer: D

Why: Static methods belong to the class, not its instances.
{% enddetails %}

Challenge 86. instanceof inheritance

Predict the exact output before opening the answer.

`javascript
class A {}
class B extends A {}
console.log(new B() instanceof A);
`

Option Output
A false
B TypeError
C true
D undefined

{% details Answer and explanation %}
Correct answer: C

Why: B instances inherit from A.prototype.
{% enddetails %}

Promises, async/await, and event loop

Challenge 87. Synchronous then microtask

Predict the exact output before opening the answer.

`javascript
Promise.resolve().then(() => console.log('promise'));
console.log('sync');
`

Option Output
A TypeError
B sync, promise
C undefined
D false

{% details Answer and explanation %}
Correct answer: B

Why: Synchronous code completes before the microtask queue runs.
{% enddetails %}

Challenge 88. Timer after synchronous code

Predict the exact output before opening the answer.

`javascript
setTimeout(() => console.log('timer'), 0);
console.log('sync');
`

Option Output
A sync, timer
B undefined
C false
D TypeError

{% details Answer and explanation %}
Correct answer: A

Why: A timer callback runs after the current task.
{% enddetails %}

Challenge 89. Microtask before timer

Predict the exact output before opening the answer.

`javascript
setTimeout(() => console.log('timer'), 0);
Promise.resolve().then(() => console.log('promise'));
console.log('sync');
`

Option Output
A undefined
B false
C TypeError
D sync, promise, timer

{% details Answer and explanation %}
Correct answer: D

Why: Microtasks run after synchronous code and before the next timer task.
{% enddetails %}

Challenge 90. Async return value

Predict the exact output before opening the answer.

`javascript
async function value() { return 2; }
value().then(console.log);
`

Option Output
A false
B TypeError
C 2
D undefined

{% details Answer and explanation %}
Correct answer: C

Why: An async function return becomes a fulfilled Promise value.
{% enddetails %}

Challenge 91. Async thrown error

Predict the exact output before opening the answer.

`javascript
async function fail() { throw 'no'; }
fail().catch(console.log);
`

Option Output
A TypeError
B no
C undefined
D false

{% details Answer and explanation %}
Correct answer: B

Why: Throwing in an async function rejects its returned Promise.
{% enddetails %}

Challenge 92. Await non-Promise value

Predict the exact output before opening the answer.

`javascript
(async () => console.log(await 3))();
`

Option Output
A 3
B undefined
C false
D TypeError

{% details Answer and explanation %}
Correct answer: A

Why: await resolves ordinary values as well as Promises.
{% enddetails %}

Challenge 93. Promise chain value

Predict the exact output before opening the answer.

`javascript
Promise.resolve(2)
.then((n) => n * 2)
.then(console.log);
`

Option Output
A undefined
B false
C TypeError
D 4

{% details Answer and explanation %}
Correct answer: D

Why: Each then receives the previous handler’s returned value.
{% enddetails %}

Challenge 94. Catch recovery value

Predict the exact output before opening the answer.

`javascript
Promise.reject('x')
.catch(() => 5)
.then(console.log);
`

Option Output
A false
B TypeError
C 5
D undefined

{% details Answer and explanation %}
Correct answer: C

Why: A catch handler can recover by returning a fulfilled value.
{% enddetails %}

Challenge 95. Finally preserves value

Predict the exact output before opening the answer.

`javascript
Promise.resolve('ok')
.finally(() => console.log('done'))
.then(console.log);
`

Option Output
A TypeError
B done, ok
C undefined
D false

{% details Answer and explanation %}
Correct answer: B

Why: finally runs first and preserves the prior fulfilled value when it does not throw.
{% enddetails %}

Challenge 96. Promise all result order

Predict the exact output before opening the answer.

`javascript
Promise.all([Promise.resolve('a'), Promise.resolve('b')])
.then(console.log);
`

Option Output
A [a, b]
B undefined
C false
D TypeError

{% details Answer and explanation %}
Correct answer: A

Why: Promise.all preserves input order in its result array.
{% enddetails %}

Challenge 97. Promise all rejection

Predict the exact output before opening the answer.

`javascript
Promise.all([Promise.resolve(1), Promise.reject('bad')])
.catch(console.log);
`

Option Output
A undefined
B false
C TypeError
D bad

{% details Answer and explanation %}
Correct answer: D

Why: Promise.all rejects when any input Promise rejects.
{% enddetails %}

Challenge 98. Promise allSettled status

Predict the exact output before opening the answer.

`javascript
Promise.allSettled([Promise.reject('x')])
.then((items) => console.log(items[0].status));
`

Option Output
A false
B TypeError
C rejected
D undefined

{% details Answer and explanation %}
Correct answer: C

Why: allSettled reports every settlement instead of rejecting early.
{% enddetails %}

Challenge 99. queueMicrotask order

Predict the exact output before opening the answer.

`javascript
queueMicrotask(() => console.log('micro'));
console.log('sync');
`

Option Output
A TypeError
B sync, micro
C undefined
D false

{% details Answer and explanation %}
Correct answer: B

Why: queueMicrotask adds work to the microtask queue.
{% enddetails %}

Challenge 100. AbortController state

Predict the exact output before opening the answer.

`javascript
const controller = new AbortController();
controller.abort();
console.log(controller.signal.aborted);
`

Option Output
A true
B undefined
C false
D TypeError

Answer and explanation
Correct answer: A

Why: abort synchronously marks the signal as aborted.


Keep practising

For deeper explanations, use the separate JavaScript Output Interview Questions series.

📰 Read the original article on Dev.to WebDev

Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.