Docsity

INF 302 JavaScript Exam, Exams of Technology

Toggle sidebar
bg1
INF 302 JavaScript Exam
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) <script>
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48
pf49
pf4a
pf4b
pf4c
pf4d
pf4e
pf4f
pf50
pf51
pf52
pf53
pf54
pf55
pf56
pf57
pf58
pf59
pf5a
pf5b
pf5c
pf5d
pf5e
pf5f
pf60
pf61
pf62
pf63
pf64

Partial preview of the text

Download INF 302 JavaScript Exam and more Exams Technology in PDF only on Docsity!

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

A) ==

B) ===

C) !=

D) !==

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.