
- 2 min read
Select one option
1 / 11
console.log(!![])
JavaScript Guess the Output #1 — quiz answer sheet, click to expand.
Answer: true
Explanation: An empty array is a truthy value in JavaScript. The double negation converts it to a boolean, resulting in true.
Answer: false
Explanation: Due to floating-point precision issues in JavaScript, 0.1 + 0.2 does not equal 0.3 exactly.
Answer: 101
Explanation: JavaScript arrays are sparse, meaning that you can set an index that is greater than the current length of the array. The length property will then reflect the highest index + 1.
Answer: object
Explanation: null is considered an object due to a historical bug that has never been fixed duo to backward compatibility
Answer: 1
Explanation: The length property of a function indicates the number of expected parameters before the first optional one, excluding rest parameters.
Answer: number
Explanation: NaN stands for 'Not a Number', but its type is actually 'number'.
Answer: 5
105
Explanation: Subtraction converts '10' to a number. The second operation is concatenation, which converts 5 to a string.
Answer: [1, 10, 2, 5]
Explanation: The sort method sorts the array elements as strings, so '10' comes before '2' and '5'.
Answer: 3 3 3
Explanation: The variable 'i' is declared with var, which has function scope. By the time the setTimeout callback executes, 'i' is 3.
Answer: 12
Explanation: The value of a is 5. a++ returns 5 and then increments a to 6. ++a increments a to 7 and returns 7. So, b = 5 + 7 = 12.
Answer: baNaNa
Explanation: The unary plus operator tries to convert the string 'a' to a number, which results in NaN. So, the expression becomes 'ba' + NaN + 'a', which results in 'baNaNa'.