




























































































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!





























































































Question 1. What is the primary role of JavaScript in web development? A) Styling web pages B) Structuring web content C) Adding interactivity and dynamic content D) Managing server databases Answer: C Explanation: JavaScript is mainly used to add interactivity and dynamic behavior to web pages, unlike HTML and CSS which handle structure and style. Question 2. Which HTML tags are used to embed JavaScript directly within an HTML document? A) B) C) Question 5. What is the scope of a variable declared with var inside a function? A) Global scope B) Local scope within the function C) Block scope D) No scope Answer: B Explanation: Variables declared with var inside a function have function scope, meaning they are accessible throughout the function. Question 6. Which data type in JavaScript represents a sequence of characters? A) Number
B) String C) Boolean D) Object Answer: B Explanation: String data type is used to represent sequences of characters in JavaScript. Question 7. Which of the following is a primitive data type in JavaScript? A) Array B) Object C) String D) Function Answer: C
Answer: B Explanation: The === operator checks for strict equality, comparing both type and value. Question 10. What does the logical AND (&&) operator do? A) Returns true if both operands are true B) Returns true if either operand is true C) Inverts the boolean value D) Compares two values for equality
Answer: A Explanation: The && operator returns true only if both operands evaluate to true. Question 11. Which operator is used for the ternary conditional operation? A)? B) : C)? : D) && Answer: C Explanation: The syntax for the ternary operator is condition? expression1 : expression2.
C) Conversion of variables to strings only D) Type checking before operation Answer: B Explanation: Implicit coercion happens automatically when JavaScript converts types during comparisons or arithmetic operations. Question 14. Which method explicitly converts a value to a number? A) String() B) Boolean() C) Number() D) parseInt() Answer: C Explanation: Number() converts its argument to a number explicitly.
Question 15. Which loop guarantees execution at least once? A) for B) while C) do...while D) for...of Answer: C Explanation: The do...while loop executes its body before checking the condition, ensuring at least one execution. Question 16. How do you declare a function in JavaScript? A) function myFunction() {} B) def myFunction() {}
Explanation: The return statement exits the function and provides a value back to the function caller. Question 18. Which ES6 feature allows default parameter values? A) function myFunc(a=5) {} B) function myFunc(a:5) {} C) function myFunc(a: default 5) {} D) function myFunc(a: default=5) {} Answer: A Explanation: Default parameters are specified with an equals sign in the function declaration. Question 19. What does the spread operator (...) do when used with objects or arrays?
A) Clones and merges objects or arrays B) Creates a new array C) Applies a function to each element D) Limits the number of elements Answer: A Explanation: The spread operator expands an iterable or object into individual elements, allowing cloning or merging. Question 20. What is a closure in JavaScript? A) A function bundled with its scope B) A variable with block scope C) A new object instance D) A syntax for loops
Question 22. In JavaScript, what does let keyword do? A) Declares a variable with block scope B) Declares a global variable C) Declares a constant D) Declares a variable with function scope Answer: A Explanation: let declares variables with block scope, unlike var which is function-scoped. Question 23. Which method is used to add an element at the end of an array? A) push() B) pop()
C) shift() D) unshift() Answer: A Explanation: push() appends one or more elements to the end of an array. Question 24. How do you access an object's property using bracket notation? A) object.property B) object['property'] C) object[property] D) Both B and C Answer: D
A) JSON.parse() B) JSON.stringify() C) Object.toJSON() D) JSON.convert() Answer: B Explanation: JSON.stringify() converts a JavaScript object to a JSON string. Question 27. How do you select an element by its ID in the DOM? A) getElementById() B) querySelector() C) getElementsByClassName() D) getElementByClass()
Answer: A Explanation: getElementById() returns the element with the specified ID. Question 28. Which property is used to change the text content of a DOM element? A) innerHTML B) textContent C) value D) Both A and B Answer: D Explanation: innerHTML and textContent both modify the content of an element; value is used for form elements.