JavaScript Interview Questions Quiz Part 6

Here are 20 JavaScript multiple-choice interview questions along with answers:


1. What is the output of the following code?

JavaScript
console.log(typeof null);
  • A. "null"
  • B. "object"
  • C. "undefined"
  • D. "number"

Answer: B. "object"


2. Which of the following is not a primitive data type in JavaScript?

  • A. Number
  • B. Object
  • C. String
  • D. Boolean

Answer: B. Object


3. What is the correct syntax to create an array in JavaScript?

  • A. var arr = {};
  • B. var arr = [];
  • C. var arr = new Array();
  • D. Both B and C

Answer: D. Both B and C


4. Which of the following methods is used to add an element to the end of an array?

  • A. push()
  • B. pop()
  • C. shift()
  • D. unshift()

Answer: A. push()


5. What is the output of the following code?

console.log(2 + "2");
  • A. 22
  • B. 4
  • C. NaN
  • D. Error

Answer: A. 22


6. How do you write an arrow function in JavaScript?

  • A. function => () {}
  • B. () => {}
  • C. => function {}
  • D. () -> {}

Answer: B. () => {}


7. What will console.log([] == false) output?

  • A. true
  • B. false
  • C. undefined
  • D. Error

Answer: A. true


8. Which keyword is used to declare a constant variable in JavaScript?

  • A. let
  • B. var
  • C. constant
  • D. const

Answer: D. const


9. What is the purpose of isNaN() in JavaScript?

  • A. Check if a value is a number
  • B. Check if a value is not a number
  • C. Check if a value is undefined
  • D. Check if a value is null

Answer: B. Check if a value is not a number


10. What does == compare in JavaScript?

  • A. Value only
  • B. Type only
  • C. Value and type
  • D. None of the above

Answer: A. Value only


11. Which of the following is used to stop event propagation?

  • A. stopPropagation()
  • B. preventDefault()
  • C. return false;
  • D. clearPropagation()

Answer: A. stopPropagation()


12. What is the purpose of JSON.stringify()?

  • A. Convert a JSON string to an object
  • B. Convert an object to a JSON string
  • C. Parse a URL string
  • D. None of the above

Answer: B. Convert an object to a JSON string


13. Which method is used to combine two or more arrays in JavaScript?

  • A. concat()
  • B. merge()
  • C. join()
  • D. add()

Answer: A. concat()


14. What is the output of the following code?

JavaScript
console.log("5" - 2);
  • A. 3
  • B. 52
  • C. "5-2"
  • D. Error

Answer: A. 3


15. Which of the following is a falsy value in JavaScript?

  • A. 0
  • B. ""
  • C. null
  • D. All of the above

Answer: D. All of the above


16. What is a closure in JavaScript?

  • A. A function inside an object
  • B. A function bundled with its lexical environment
  • C. A block of code inside curly braces
  • D. None of the above

Answer: B. A function bundled with its lexical environment


17. How can you check if a variable is an array?

  • A. typeof variable === "array"
  • B. Array.isArray(variable)
  • C. variable instanceof Array
  • D. Both B and C

Answer: D. Both B and C


18. What is the purpose of setTimeout()?

  • A. Repeats execution of code at specified intervals
  • B. Executes a function after a delay
  • C. Stops the execution of code
  • D. None of the above

Answer: B. Executes a function after a delay


19. What will console.log(!!"") output?

  • A. true
  • B. false
  • C. undefined
  • D. Error

Answer: B. false


20. Which JavaScript feature allows functions to operate on objects irrespective of their type?

  • A. Closures
  • B. Prototypes
  • C. Polymorphism
  • D. Hoisting

Answer: C. Polymorphism


Let me know if you’d like further clarification or more questions!

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *