1. What is the primary purpose of JavaScript?
To style HTML content
To add interactivity to websites
To manage databases
To create server-side applications
2. Which keyword is used to declare a variable in JavaScript?
3. What type of language is JavaScript?
Compiled
Interpreted
Assembly
Machine Code
4. What is the output of `3 + "3"` in JavaScript?
5. Which of these is NOT a JavaScript data type?
Number
String
Boolean
Character
6. How do you write a single-line comment in JavaScript?
/* comment */
// comment
<!-- comment -->
' comment
7. What is the purpose of the `typeof` operator?
To determine the data type of a variable
To check if a variable is defined
To convert a variable to a string
To perform mathematical operations
8. Which method is used to access HTML elements using JavaScript?
getElementByID
querySelector
Both getElementByID and querySelector
accessElement
9. What does DOM stand for in JavaScript?
Document Object Model
Data Order Management
Design Object Module
Direct Object Manipulation
10. How do you call a function in JavaScript?
call myFunction
myFunction()
invoke myFunction
function myFunction()
11. Which operator is used for concatenation in JavaScript?
12. What is an anonymous function in JavaScript?
A function without a name
A function that is not defined
A function that is called automatically
A function defined inside another function
13. What will `NaN === NaN` return in JavaScript?
14. Which method adds a new element to the end of an array?
pop()
push()
shift()
unshift()
15. What is the purpose of `addEventListener()` in JavaScript?
To remove an event listener
To attach an event handler to an element
To trigger an event
To prevent default events
16. What is a closure in JavaScript?
A function that is defined but not called
A function along with its lexical environment
A function that always returns a value
A function used to close HTML tags
17. How do you write an IF statement in JavaScript?
if (condition) {}
if condition then {}
if condition {} else {}
if condition then else {}
18. What is the purpose of the `parseInt()` function?
To convert a string to a floating-point number
To convert a string to an integer
To check if a value is an integer
To format a number as an integer
19. What is the difference between `==` and `===` in JavaScript?
`==` compares value and type, `===` compares only value
`===` compares value and type, `==` compares only value
There is no difference
`==` is for assignment, `===` is for comparison
20. Which loop executes a block of code at least once, and then repeatedly as long as the condition is true?
for loop
while loop
do...while loop
forEach loop
21. What is the global object in client-side JavaScript?
window
globalThis
document
browser
22. How do you prevent default behavior of an event in JavaScript?
stopDefault()
preventDefault()
cancelEvent()
disableDefault()
23. What is the purpose of `JSON.parse()`?
To convert a JavaScript object to a JSON string
To parse a JSON string into a JavaScript object
To validate JSON syntax
To stringify a JavaScript object
24. What is the purpose of the `finally` block in a `try...catch...finally` statement?
To handle errors
To execute code after the `catch` block, regardless of the outcome
To define variables used in `try` and `catch` blocks
To conditionally execute code based on whether an error occurred
25. Which array method removes the first element from an array and returns that element?
pop()
shift()
splice()
slice()