JavaScript Multiple Choice Questions (MCQs)
1. Core JavaScript
Q1. Which of the following is not a reserved word in JavaScript?
- A) interface
- B) throws
- C) program
- D) short
Answer: C. program is not a reserved keyword in JavaScript.
Q2. What is the output of typeof null in JavaScript?
- A) "null"
- B) "undefined"
- C) "object"
- D) "number"
Answer: C. This is a well-known bug/quirk in JavaScript since its first version. typeof null returns "object".
2. ES6+ Features
Q3. Which keyword is used to declare a block-scoped variable?
- A) var
- B) let
- C) function
- D) def
Answer: B. The let keyword (along with const) provides block scoping, unlike var which provides function scoping.
Q4. What is the output of [] == false?
- A) true
- B) false
- C) TypeError
- D) undefined
Answer: A. In JavaScript, an empty array [] is coerced to an empty string "", which is then coerced to the number 0. false is also coerced to 0, so they are loosely equal.
3. Asynchronous JavaScript
Q5. Which method is used to wait for multiple promises to resolve?
- A)
Promise.all() - B)
Promise.wait() - C)
Promise.every() - D)
Promise.resolveAll()
Answer: A. Promise.all() takes an iterable of promises and returns a single Promise that resolves when all of the input's promises have resolved.