1. What keyword creates a block-scoped variable that can be reassigned?
let score = 10;
2. Which statement correctly creates a function named sum?
function sum(a, b) { return a + b; }
3. What will this log?
console.log(typeof null);
4. Which method adds a value to the end of an array?
let a = [1,2]; a.push(3);
5. What does === test for?
6. Which of these creates an object with a property name?
let obj = { name: 'Sam' };
7. What will [1,2,3].map(x => x * 2) return?
[1,2,3].map(x => x * 2);
8. Which is true about const?
9. What is hoisting in JavaScript?
10. Which method parses a JSON string into an object?
JSON.parse('{"a":1}');
11. What will this expression return: [...'abc'] ?
[...'abc']
12. How do you schedule a function to run after 2 seconds?
setTimeout(fn, 2000);
13. Which event fires when the DOM has been loaded (but before images load)?
14. What does Array.prototype.filter return?
15. Which of these accesses the element with id ‘app’?
document.getElementById('app')
16. What is a Promise?
17. How do you catch errors from a Promise?
promise.then(...).catch(err => ...)
18. What does async/await provide?
19. Which built-in method returns the characters in a string as uppercase?
'hi'.toUpperCase()
20. How do you remove the first element from an array?
let a = [1,2,3]; a.shift();
21. Which operator spreads an array into separate arguments?
Math.max(...[1,2,3])
22. What will 0 == '0' evaluate to?
23. Which method trims whitespace from both ends of a string?
' hi '.trim()
24. What will typeof [] return?
25. Which regex flag makes matching case-insensitive?
/abc/i
26. Which built-in object provides methods for rounding and generating random numbers?
27. What is the output of typeof NaN?
28. Which DOM API finds elements by class name?
document.getElementsByClassName('btn')
29. What does event.preventDefault() do?
30. Which of these creates a shallow copy of an object?
let copy = Object.assign({}, obj);
31. What does document.createElement('div') do?
32. Which method returns the index of the first match in an array?
33. Which will parse integer from string?
34. Which of the following is a truthy value?
35. What does Object.keys(obj) return?
36. Which will stop propagation of an event so it doesn’t bubble up?
37. Which creates a new object that delegates to a specified prototype?
38. Which will convert a value to a number, returning NaN on failure?
39. What will 0 === -0 evaluate to?
40. Which statement throws an exception?
41. Which returns milliseconds since 1970-01-01 UTC?
42. What does call() do on functions?
43. Which removes a property from an object?
delete obj.prop;
44. Which is true about arrow functions?
45. What is event delegation?
46. Which array method reduces values to a single value?
47. What does void 0 evaluate to?
48. Which error type indicates invalid JSON or code syntax?
49. Which returns true if at least one element passes a predicate?
arr.some(x => x > 5)
50. Which method adds an element as the last child of a node?
parent.appendChild(child)