21. What is the output of console.log(1 + "1")?
- a) "11"
- b) 2
- c) NaN
- d) TypeError
1 becomes "1").
Test your knowledge of JavaScript with these interactive multiple-choice questions.
21. What is the output of console.log(1 + "1")?
1 becomes "1").
22. Which method flattens a nested array?
flat() creates a new array with all sub-array elements concatenated (e.g., [1, [2]].flat() → [1, 2]).
23. What does !!"false" evaluate to?
!! operator converts values to booleans. Non-empty strings are truthy.
24. Which statement about var is true?
var declarations are function-scoped (not block-scoped like let/const).
25. What is the purpose of Object.freeze()?
Object.freeze() makes an object immutable (no additions/deletions/changes).
26. What is the output of console.log(typeof [])?
27. Which method converts an object to an array of its values?
Object.values(obj) returns an array of the object's property values.
28. What does setTimeout() return?
setTimeout() returns a numeric ID for clearing the timer with clearTimeout().
29. What is the result of Boolean([])?
30. Which operator returns the remainder of a division?
%) returns the remainder (e.g., 10 % 3 → 1).
31. What is hoisting in JavaScript?
32. What is the output of console.log(3 == "3")?
==) coerces types, so "3" becomes 3.
33. Which method removes the first element from an array?
shift() removes and returns the first element (mutating the original array).
34. What does Array.isArray([]) return?
Array.isArray() checks if the argument is an array.
35. What is the default value of an uninitialized variable?
undefined.
36. Which method merges two or more arrays?
concat() returns a new array combining the originals (e.g., [1].concat([2]) → [1, 2]).
37. What is the output of console.log("5" - 3)?
- operator coerces "5" to a number, resulting in numeric subtraction.
38. Which keyword stops a loop iteration and moves to the next?
continue skips the current iteration and proceeds to the next.
39. What is the output of console.log(+"10")?
+ operator converts strings to numbers.
40. Which method checks if an array includes a value?
includes() returns true if the value exists in the array.