500 Javascript MCQ Interview Questions

Question 1: Which of the following is the correct syntax to declare a JavaScript variable?
Answer: A) var variableName;
Question 2: What is the output of the following code: console.log(typeof null);?
Answer: B) object
Question 3: Which of the following is not a JavaScript data type?
Answer: D) Character
Question 4: Which of the following methods can be used to convert a string to a number in JavaScript?
Answer: A) parseInt(), D) Number()
Question 5: What is the correct way to create a function in JavaScript?
Answer: B) function myFunction() { }
Question 6: What will be the output of console.log(0.1 + 0.2 === 0.3);?
Answer: B) false
Question 7: Which of the following keywords is used to define a constant in JavaScript?
Answer: A) const
Question 8: What is the purpose of the this keyword in JavaScript?
Answer: C) Refers to the object that is executing the current function
Question 9: Which method is used to remove the last element from an array in JavaScript?
Answer: A) pop()
Question 10: Which of the following is an example of a first-class function?
Answer: D) All of the above
Question 11: How can you create an object in JavaScript?
Answer: D) All of the above
Question 12: What is the output of console.log(typeof NaN);?
Answer: A) Number
Question 13: Which of the following statements is used to create a conditional statement in JavaScript?
Answer: D) Both A and B
Question 14: What does the Math.random() function return?
Answer: B) A random floating-point number between 0 and 1
Question 15: Which operator is used to assign a value to a variable in JavaScript?
Answer: B) =
Question 16: What is the purpose of the JSON.stringify() method?
Answer: A) Converts a JSON object into a string
Question 17: How do you declare a JavaScript array?
Answer: A) var arr = []; , D) var arr = new Array();
Question 18: Which of the following is a JavaScript framework?
Answer: D) All of the above
Question 19: What will console.log(2 + '2'); output?
Answer: B) 22
Question 20: What is the purpose of the setTimeout() function in JavaScript?
Answer: A) To create a delay in the execution of a function
Question 21: Which of the following is a way to handle exceptions in JavaScript?
Answer: D) Both A and C
Question 22: What is the output of console.log('Hello' + 5 + 10);?
Answer: A) Hello510
Question 23: Which built-in method combines two or more arrays in JavaScript?
Answer: A) concat()
Question 24: What is the purpose of the localStorage object?
Answer: B) To store data permanently in the user's browser
Question 25: How do you declare a variable in JavaScript?
Answer: D) All of the above
Question 26: What will console.log(!!null); output?
Answer: B) false
Question 27: Which of the following methods can be used to iterate over an array?
Answer: D) All of the above
Question 28: How can you add a comment in JavaScript?
Answer: D) Both A and B
Question 29: Which method is used to access the first element of an array?
Answer: C) array[0]
Question 30: What will console.log(1 == '1'); output?
Answer: A) true
Question 31: Which of the following is a valid way to declare an object?
Answer: D) Both A and B
Question 32: What does the slice() method do in JavaScript?
Answer: C) Returns a shallow copy of a portion of an array
Question 33: Which of the following functions can be used to read user input in JavaScript?
Answer: A) prompt()
Question 34: What is the output of console.log([1] == true);?
Answer: A) true
Question 35: Which method is used to find the index of an element in an array?
Answer: D) Both A and B
Question 36: Which operator is used to compare both value and type in JavaScript?
Answer: B) ===
Question 37: What is the purpose of the typeof operator?
Answer: A) To determine the type of a variable
Question 38: How can you check if a variable is an array in JavaScript?
Answer: D) Both A and B
Question 39: Which function is used to parse a JSON string into a JavaScript object?
Answer: B) JSON.parse()
Question 40: Which of the following is a truthy value in JavaScript?
Answer: D) 1
Question 41: What will be the output of console.log(typeof []);?
Answer: B) object
Question 42: How can you create a copy of an array in JavaScript?
Answer: D) All of the above
Question 43: Which of the following can be used to trigger a function in JavaScript?
Answer: D) All of the above
Question 44: What is a closure in JavaScript?
Answer: A) A function with access to its own scope, the outer function's scope, and the global scope
Question 45: What is event delegation in JavaScript?
Answer: A) Attaching an event handler to a parent element
Question 46: What is the purpose of the 'this' keyword in JavaScript?
Answer: D) Both B and C
Question 47: How can you prevent an event from bubbling up in JavaScript?
Answer: D) Both A and C
Question 48: What is the purpose of the fetch() function in JavaScript?
Answer: D) All of the above
Question 49: Which of the following is a way to define a function in JavaScript?
Answer: D) All of the above
Question 50: What is a promise in JavaScript?
Answer: A) A way to handle asynchronous operations

Showing 1-50 of 500 questions

Answer Key

  • 1. B) JSON.parse()
  • 2. A) number
  • 3. A) number
  • 4. A) number
  • 5. A) number
  • 6. A) number
  • 7. A) number
  • 8. A) number
  • 9. A) number
  • 10. A) number
  • 11. A) number
  • 12. A) number
  • 13. A) number
  • 14. A) number
  • 15. A) number
  • 16. A) number
  • 17. A) number
  • 18. A) number
  • 19. A) number
  • 20. A) number
  • 21. A) number
  • 22. A) number
  • 23. A) number
  • 24. A) number
  • 25. A) number
  • 26. A) number
  • 27. A) number
  • 28. A) number
  • 29. A) number
  • 2. A) number
  • 2. A) number
  • 2. A) number
  • 2. A) number
  • 2. A) number
  • 2. A) number
  • 2. A) number
  • 2. A) number
  • 2. A) number
  • 2. A) number
  • 2. A) number
  • 2. A) number
  • 2. A) number
  • 2. A) number
  • 2. A) number
  • 2. A) number
  • 2. A) number
  • 2. A) number
Contact Tech Spakes Training