← All topics

JavaScript Junior interview questions and answers

75 questions for a JavaScript (Junior) interview - with correct answers, explanations and links to the docs.

Take this quiz
  1. 1.How many data types does JavaScript have according to the specification?
  2. 2.What does typeof null return?
  3. 3.What does typeof NaN return?
  4. 4.How does let differ from var?
  5. 5.What happens?
  6. 6.What does this code print?
  7. 7.What does this code print?
  8. 8.How does == differ from ===?
  9. 9.How does null differ from undefined?
  10. 10.What does NaN === NaN return?
  11. 11.What does 0.1 + 0.2 === 0.3 evaluate to?
  12. 12.What are '5' + 3 and '5' - 3?
  13. 13.Which of these values is falsy?
  14. 14.How does count || 10 differ from count ?? 10 when count = 0?
  15. 15.What does user?.address?.city return if user = {}?
  16. 16.How does an arrow function differ from a regular one?
  17. 17.Can you call a function before its declaration?
  18. 18.What does this code print?
  19. 19.What is a closure?
  20. 20.What does this code print?
  21. 21.What does const copy = { ...original } do?
  22. 22.What does [1, 2, 3].map(x => x * 2) return?
  23. 23.What does [1, 2, 3].forEach(x => x * 2) return?
  24. 24.What does [1, 2, 3, 4].reduce((sum, x) => sum + x, 0) return?
  25. 25.How does for...in differ from for...of?
  26. 26.How does slice differ from splice?
  27. 27.What do [NaN].includes(NaN) and [NaN].indexOf(NaN) return?
  28. 28.What does this code print?
  29. 29.What does sum(1, 2, 3) return?
  30. 30.What does Math.max(...[3, 7, 2]) return?
  31. 31.What does JSON.stringify({ a: 1, b: undefined, c: () => 1 }) return?
  32. 32.In what order are the numbers printed?
  33. 33.Which states can a promise be in?
  34. 34.What does an async function return?
  35. 35.Why won't catch catch the error?
  36. 36.What does const arr = ['a', 'b']; console.log(arr[20]); print?
  37. 37.What does this code print?
  38. 38.How do you reliably check that a value is an array?
  39. 39.Why is textContent safer than innerHTML for displaying user text?
  40. 40.Why is addEventListener better than el.onclick = handler?
  41. 41.What does event.preventDefault() do?
  42. 42.What is event bubbling?
  43. 43.What is event delegation about?
  44. 44.How does localStorage differ from sessionStorage?
  45. 45.What does localStorage.getItem('n') return after localStorage.setItem('n', 5)?
  46. 46.How does DOMContentLoaded differ from load?
  47. 47.How does Map differ from a plain object?
  48. 48.How do you quickly remove duplicates from an array of primitives?
  49. 49.What does the 'use strict' directive give you?
  50. 50.How do you find the first element with the card class on the page?
  51. 51.Does this code throw an error?
  52. 52.What does a template literal give you compared to string concatenation?
  53. 53.What does arr.length = 0 do?
  54. 54.What does [1, 2].push(3) return?
  55. 55.How does find differ from filter?
  56. 56.What is the difference between some and every?
  57. 57.What does this code print in a classic (non-strict) script?
  58. 58.What type does (1.005).toFixed(2) return?
  59. 59.What does greet() return?
  60. 60.What are title and year after this destructuring?
  61. 61.What does [a, b] = [b, a] do?
  62. 62.How does "toString" in obj differ from Object.hasOwn(obj, "toString") for obj = {}?
  63. 63.What does 0 && "hello" evaluate to?
  64. 64.Which case runs for x = "1"?
  65. 65.When does a finally block run?
  66. 66.How does Number.isNaN("abc") differ from isNaN("abc")?
  67. 67.What does Math.round(-2.5) return?
  68. 68.What does a function return if it has no return statement?
  69. 69.Why does document.querySelectorAll("li").map(...) throw?
  70. 70.What does el.classList.toggle("open") do?
  71. 71.In a click handler attached to <ul>, how do event.target and event.currentTarget differ?
  72. 72.What happens with JSON.parse("{ name: 'Ann' }")?
  73. 73.What does [1, [2, [3]]].flat() return?
  74. 74.What is a callback?
  75. 75.What does ["a", "b", "c"].at(-1) return?