Multiple-choice questions (MCQs) based on JavaScript
1. What does DOM stand for?
A) Document Object Model
B) Data Object Model
C) Document Oriented Model
D) Display Object Model
Answer: A) Document Object Model
2. Which keyword is used to declare variables in JavaScript?
A) dim
B) var
C) int
D) string
Answer: B) var
3. What does the `typeof` operator return for an array?
A) "array"
B) "object"
C) "function"
D) "undefined"
Answer: B) "object"
4. Which method is used to add a new element to the end of an array in JavaScript?
A) push()
B) append()
C) addToEnd()
D) add()
Answer: A) push()
5. What will the following code output: `console.log(2 + '2')`?
A) 22
B) 4
C) "22"
D) NaN
Answer: C) "22"
6. Which symbol is used for single-line comments in JavaScript?
A) //
B) #
C) --
D) /*
Answer: A) //
7. What is the result of `typeof undefined`?
A) "undefined"
B) "null"
C) "object"
D) "string"
Answer: A) "undefined"
8. Which function is used to parse a string to an integer in JavaScript?
A) parseInt()
B) stringToInt()
C) toInt()
D) parseInteger()
Answer: A) parseInt()
9. Which event is triggered when an HTML form is submitted?
A) onsubmit
B) onsubmitting
C) onsend
D) onsubmitform
Answer: A) onsubmit
10. What does the `!==` operator mean in JavaScript?
A) Not equal in value or type
B) Not equal in value only
C) Equal in value and type
D) Equal in value but not in type
Answer: A) Not equal in value or type
11. What will the following code output: `console.log(3 == '3')`?
A) true
B) false
C) NaN
D) SyntaxError
Answer: A) true
12. Which method is used to remove the last element from an array in JavaScript?
A) removeLast()
B) pop()
C) deleteLast()
D) removeFromEnd()
Answer: B) pop()
13. What is the output of `console.log(typeof NaN)`?
A) "number"
B) "NaN"
C) "undefined"
D) "string"
Answer: A) "number"
14. Which loop executes the code block as long as the condition evaluates to true?
A) for loop
B) while loop
C) do-while loop
D) switch loop
Answer: B) while loop
15. What does the `parseFloat()` function do in JavaScript?
A) Parses a string and returns an integer
B) Parses a string and returns a float number
C) Parses a string and returns a boolean value
D) Parses a string and returns a character
Answer: B) Parses a string and returns a float number
16. What is the result of `console.log(10 / '2')`?
A) 5
B) "5"
C) NaN
D) SyntaxError
Answer: A) 5
17. How do you access the first element of an array in JavaScript?
A) arr[1]
B) arr.first()
C) arr[0]
D) arr.start()
Answer: C) arr[0]
18. Which function is used to round a number to the nearest integer in JavaScript?
A) round()
B) ceil()
C) floor()
D) Math.round()
Answer: D) Math.round()
19. What does the `splice()` method do in JavaScript?
A) Slices a portion of an array and returns a new array
B) Removes elements from an array and returns the removed elements
C) Adds new elements to an array at a specified index
D) Reverses the elements of an array
Answer: B) Removes elements from an array and returns the removed elements
20. Which function is used to create a new object with the specified prototype object and properties in JavaScript?
A) Object.create()
B) Object.build()
C) Object.define()
D) Object.construct()
Answer: A) Object.create()
21. What will the following code output: `console.log(typeof (typeof 1))`?
A) "number"
B) "string"
C) "object"
D) "undefined"
Answer: B) "string"
22. Which function is used to convert a string to uppercase in JavaScript?
A) toUpper()
B) uppercase()
C) toUpperCase()
D) upperCase()
Answer: C) toUpperCase()
23. What is the output of `console.log(1 + 2 + '3')`?
A) 6
B) "123"
C) "33"
D) SyntaxError
Answer: C) "33"
24. Which method is used to join the elements of an array into a string in JavaScript?
A) concat()
B) join()
C) merge()
D) combine()
Answer: B) join()
25. What is the purpose of the `this` keyword in JavaScript?
A) Refers to the current function
B) Refers to the global object
C) Refers to the parent object
D) Refers to the current object
Answer: D) Refers to the current object
26. What will the following code output: `console.log(1 == true)`?
A) true
B) false
C) SyntaxError
D) TypeError
Answer: A) true
27. Which function is used to determine if a variable is an array in JavaScript?
A) isArray()
B) isArr()
C) arrayCheck()
D) checkArray()
Answer: A) isArray()
28. What is the result of `console.log(2 ** 3)`?
A) 6
B) 8
C) 2^3
D) SyntaxError
Answer: B) 8
29. How do you declare a function in JavaScript?
A) function myFunction() {}
B) def myFunction() {}
C) void myFunction() {}
D) func myFunction() {}
Answer: A) function myFunction() {}
30. What does the `isNaN()` function return for non-numeric values in JavaScript?
A) true
B) false
C) SyntaxError
D) TypeError
Answer: A) true
These questions cover various aspects of JavaScript syntax, operators, functions, and methods.
--Code With VDK