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.How many data types does JavaScript have according to the specification?
- 2.What does
typeof nullreturn? - 3.What does
typeof NaNreturn? - 4.How does
letdiffer fromvar? - 5.What happens?
- 6.What does this code print?
- 7.What does this code print?
- 8.How does
==differ from===? - 9.How does
nulldiffer fromundefined? - 10.What does
NaN === NaNreturn? - 11.What does
0.1 + 0.2 === 0.3evaluate to? - 12.What are
'5' + 3and'5' - 3? - 13.Which of these values is falsy?
- 14.How does
count || 10differ fromcount ?? 10whencount = 0? - 15.What does
user?.address?.cityreturn ifuser = {}? - 16.How does an arrow function differ from a regular one?
- 17.Can you call a function before its declaration?
- 18.What does this code print?
- 19.What is a closure?
- 20.What does this code print?
- 21.What does
const copy = { ...original }do? - 22.What does
[1, 2, 3].map(x => x * 2)return? - 23.What does
[1, 2, 3].forEach(x => x * 2)return? - 24.What does
[1, 2, 3, 4].reduce((sum, x) => sum + x, 0)return? - 25.How does
for...indiffer fromfor...of? - 26.How does
slicediffer fromsplice? - 27.What do
[NaN].includes(NaN)and[NaN].indexOf(NaN)return? - 28.What does this code print?
- 29.What does
sum(1, 2, 3)return? - 30.What does
Math.max(...[3, 7, 2])return? - 31.What does
JSON.stringify({ a: 1, b: undefined, c: () => 1 })return? - 32.In what order are the numbers printed?
- 33.Which states can a promise be in?
- 34.What does an
asyncfunction return? - 35.Why won't
catchcatch the error? - 36.What does
const arr = ['a', 'b']; console.log(arr[20]);print? - 37.What does this code print?
- 38.How do you reliably check that a value is an array?
- 39.Why is
textContentsafer thaninnerHTMLfor displaying user text? - 40.Why is
addEventListenerbetter thanel.onclick = handler? - 41.What does
event.preventDefault()do? - 42.What is event bubbling?
- 43.What is event delegation about?
- 44.How does
localStoragediffer fromsessionStorage? - 45.What does
localStorage.getItem('n')return afterlocalStorage.setItem('n', 5)? - 46.How does
DOMContentLoadeddiffer fromload? - 47.How does
Mapdiffer from a plain object? - 48.How do you quickly remove duplicates from an array of primitives?
- 49.What does the
'use strict'directive give you? - 50.How do you find the first element with the
cardclass on the page? - 51.Does this code throw an error?
- 52.What does a template literal give you compared to string concatenation?
- 53.What does
arr.length = 0do? - 54.What does
[1, 2].push(3)return? - 55.How does
finddiffer fromfilter? - 56.What is the difference between
someandevery? - 57.What does this code print in a classic (non-strict) script?
- 58.What type does
(1.005).toFixed(2)return? - 59.What does
greet()return? - 60.What are
titleandyearafter this destructuring? - 61.What does
[a, b] = [b, a]do? - 62.How does
"toString" in objdiffer fromObject.hasOwn(obj, "toString")forobj = {}? - 63.What does
0 && "hello"evaluate to? - 64.Which case runs for
x = "1"? - 65.When does a
finallyblock run? - 66.How does
Number.isNaN("abc")differ fromisNaN("abc")? - 67.What does
Math.round(-2.5)return? - 68.What does a function return if it has no
returnstatement? - 69.Why does
document.querySelectorAll("li").map(...)throw? - 70.What does
el.classList.toggle("open")do? - 71.In a click handler attached to
<ul>, how doevent.targetandevent.currentTargetdiffer? - 72.What happens with
JSON.parse("{ name: 'Ann' }")? - 73.What does
[1, [2, [3]]].flat()return? - 74.What is a callback?
- 75.What does
["a", "b", "c"].at(-1)return?