COS107 (JAVASCRIPT PRACTICE QUESTIONS)
Part 1: Introduction, History, and Setup
1. What is the primary function of JavaScript in web development?
A) To define the structure of the webpage
B) To control the style and layout
C) To add behavior and interactivity
D) To manage database connections
2. Which core web technology is responsible for defining the structure of a webpage?
A) CSS
B) JavaScript
C) HTML
D) SQL
3. Who created JavaScript?
A) Bill Gates
B) Brendan Eich
C) Steve Jobs
D) James Gosling
4. In which year was JavaScript created?
A) 1990
B) 1995
C) 1999
D) 2015
5. What was the original name of JavaScript when it was first developed?
A) LiveScript
B) JScript
C) Mocha
D) ECMAScript
6. Which company did Brendan Eich work for when he created JavaScript?
A) Microsoft
B) Sun Microsystems
C) Netscape Communications
D) Google
7. Why was the name changed to "JavaScript"?
A) It was written in Java
B) To ride on the popularity of the Java programming language
C) It was a script for coffee machines
D) It was developed by Sun Microsystems
8. Which organization standardized JavaScript?
A) W3C
B) ECMA (European Computer Manufacturers Association)
C) IEEE
D) ISO
9. What significant feature was introduced in ECMAScript 3 (1999)?
A) Arrow functions
B) JSON support
C) Regular expressions and better error handling
D) Classes
10. Which version of JavaScript introduced let, const, and arrow functions?
A) ECMAScript 3
B) ECMAScript 5
C) ES6 (ES2015)
D) ECMAScript 2020
11. JavaScript can be used on servers via which technology?
A) React
B) [Link]
C) jQuery
D) TypeScript
12. Which HTML tag is used to write inline JavaScript?
A) <js>
B) <javascript>
C) <script>
D) <code>
13. What is the keyboard shortcut to open developer tools in most browsers?
A) Ctrl+C
B) Ctrl+Shift+I (or Cmd+Option+I on Mac)
C) Alt+F4
D) F5
14. What is the file extension for an external JavaScript file?
A) .java
B) .html
C) .js
D) .script
15. Which attribute is used to link an external JavaScript file in the <script> tag?
A) href
B) link
C) src
D) rel
16. Where is the [Link]() output displayed?
A) On the webpage body
B) In a popup alert
C) In the browser console
D) In the URL bar
17. What is a key advantage of using external JavaScript files?
A) It runs faster
B) It allows reuse of code across multiple HTML files
C) It does not require HTML
D) It is the only way to write JavaScript
Answers Part 1: 1: C | 2: C | 3: B | 4: B | 5: C | 6: C | 7: B | 8: B | 9: C | 10: C | 11: B | 12: C |
13: B | 14: C | 15: C | 16: C | 17: B
Part 2: Variables, Data Types, and Comments
18. Which keyword is NOT used to declare a variable in JavaScript?
A) var
B) let
C) const
D) int
19. Which symbol creates a single-line comment in JavaScript?
A) ``
B) /* */
C) //
D) #
20. How do you create a multi-line comment?
A) // ... //
B) /* ... */
C) ``
D) ** ... **
21. Primitive data types in JavaScript are:
A) Mutable
B) Immutable
C) Objects
D) Arrays
22. Which of the following is NOT a primitive data type?
A) String
B) Number
C) Boolean
D) Array
23. What is the output of typeof null?
A) 'null'
B) 'undefined'
C) 'object'
D) 'number'
24. Which data type represents a logical value of true or false?
A) String
B) Boolean
C) Object
D) Symbol
25. What is the value of a variable that has been declared but not assigned a value?
A) null
B) 0
C) undefined
D) false
26. How are Strings enclosed in JavaScript?
A) Only double quotes
B) Only single quotes
C) Single quotes, double quotes, or backticks
D) Parentheses
27. Which data type is used for integers larger than Number.MAX_SAFE_INTEGER?
A) HugeInt
B) Long
C) BigInt
D) Double
28. let person = { name: 'John', age: 25 }; is an example of which data type?
A) Array
B) Object
C) String
D) Symbol
29. Arrays in JavaScript are a special type of:
A) String
B) Number
C) Object
D) Boolean
30. Which operator is used to check the type of a variable?
A) checkType
B) typeOf
C) typeof
D) instanceOf
31. let x = null; represents:
A) An undefined value
B) An explicitly empty or non-existent value
C) A zero value
D) A syntax error
32. What constitutes a "Complex" or "Non-Primitive" data type?
A) They are immutable
B) They represent a single value
C) They represent collections or objects and are mutable
D) They are always numbers
33. What is 1e6 in JavaScript?
A) A string
B) Scientific notation for 1,000,000
C) A variable name
D) An error
Answers Part 2: 18: D | 19: C | 20: B | 21: B | 22: D | 23: C | 24: B | 25: C | 26: C | 27: C |
28: B | 29: C | 30: C | 31: B | 32: C | 33: B
Part 3: String and Array Methods
34. Which property returns the number of characters in a string?
A) size
B) count
C) length
D) index
35. What does [Link]() do?
A) Capitalizes the first letter only
B) Converts all characters to uppercase
C) Makes the text bold
D) Increases font size
36. Which method checks if a substring exists in a string?
A) has()
B) exist()
C) contains()
D) includes()
37. What is the output of 'JavaScript'.slice(0, 4)?
A) 'Java'
B) 'Script'
C) 'Jav'
D) 'avaS'
38. Which method replaces a part of a string?
A) switch()
B) change()
C) replace()
D) swap()
39. Which method adds an element to the end of an array?
A) pop()
B) push()
C) shift()
D) unshift()
40. Which method removes the last element from an array?
A) pop()
B) push()
C) delete()
D) remove()
41. Which method removes the first element from an array?
A) shift()
B) unshift()
C) pop()
D) slice()
42. Which method adds an element to the beginning of an array?
A) push()
B) pop()
C) unshift()
D) shift()
43. [Link]('banana') returns:
A) The value 'banana'
B) The index of the first occurrence of 'banana'
C) True if 'banana' exists
D) The last index of 'banana'
44. Which method joins all array elements into a single string?
A) concat()
B) merge()
C) join()
D) stringify()
45. If let fruits = ['apple', 'banana']; and you run [Link](), what is left in fruits?
A) ['banana']
B) ['apple']
C) []
D) ['apple', 'banana']
46. If text = "Hello", what is [Link]()?
A) "HELLO"
B) "Hello"
C) "hello"
D) "hELLO"
47. Strings in JavaScript are defined as:
A) Mutable objects
B) Immutable primitive types
C) Arrays of characters
D) Numbers
48. Can let bigNumber = 1e6; be considered a number type?
A) Yes
B) No, it is a string
C) No, it is a BigInt
D) No, it is a Symbol
Answers Part 3: 34: C | 35: B | 36: D | 37: A | 38: C | 39: B | 40: A | 41: A | 42: C | 43: B | 44:
C | 45: B | 46: C | 47: B | 48: A
Part 4: Conditional Statements
49. Which statement executes a block of code only if a condition is true?
A) else
B) if
C) for
D) switch
50. What is the correct syntax for an if statement?
A) if condition { }
B) if (condition) { }
C) if {condition}
D) call if (condition)
51. Which statement executes code if the if condition is false?
A) then
B) else
C) elif
D) default
52. What allows testing multiple conditions in sequence?
A) if...else
B) switch
C) if...else if...else
D) ternary
53. The syntax condition ? valueIfTrue : valueIfFalse is known as:
A) The Switch Operator
B) The Binary Operator
C) The Ternary Operator
D) The Logical Operator
54. In a switch statement, what keyword stops the execution of code inside a case?
A) stop
B) return
C) break
D) exit
55. What keyword is used in a switch statement if no case matches?
A) else
B) default
C) catch
D) otherwise
56. In the code let message = age >= 18 ? 'Adult' : 'Minor';, if age is 20, what is
message?
A) 'Minor'
B) 'Adult'
C) undefined
D) true
57. If score = 85, and the logic is if (score >= 90) 'A' else if (score >= 80) 'B', what is the
grade?
A) A
B) B
C) C
D) F
58. Conditional statements allow a program to:
A) Repeat code indefinitely
B) Make decisions
C) Store data
Answers Part 4: 49: B | 50: B | 51: B | 52: C | 53: C | 54: C | 55: B | 56: B | 57: B | 58: B
Part 5: Loops
59. What are loops used for?
A) To make decisions
B) To repeat a block of code as long as a condition is true
C) To define variables
D) To stop the program
60. Which loop executes a block of code a specific number of times?
A) while
B) do...while
C) for
D) if
61. What are the three parts of a for loop?
A) initialization, condition, increment
B) start, stop, step
C) variable, array, action
D) condition, code, break
62. Which loop executes the code block at least once before checking the condition?
A) for
B) while
C) do...while
D) foreach
63. The while loop executes as long as the condition is:
A) False
B) Null
C) True
D) Undefined
64. Which loop is best for iterating over array properties?
A) for...in
B) while
C) do...while
D) if...else
65. Which loop is best for iterating over iterable objects like arrays?
A) for...in
B) for...of
C) while
D) switch
66. In for (let i = 0; i < 5; i++), what is the final value of i that breaks the loop?
A) 4
B) 5
C) 6
D) 0
Answers Part 5: 59: B | 60: C | 61: A | 62: C | 63: C | 64: A | 65: B | 66: B
Part 6: Functions
67. A function is a reusable block of code designed to:
A) Store data
B) Perform a specific task
C) Loop forever
D) Style HTML
68. Which keyword is used to define a function?
A) func
B) def
C) function
D) method
69. Input values passed to a function are called:
A) Variables
B) Parameters
C) Keys
D) Returns
70. What keyword sends a value back to the code that called the function?
A) send
B) output
C) return
D) back
71. If a function does not have a return statement, what does it return?
A) null
B) 0
C) undefined
D) false
72. const add = (a, b) => a + b; is an example of:
A) A Function Declaration
B) An Arrow Function
C) A Class
D) A Loop
73. A function assigned to a variable is called:
A) A Function Declaration
B) A Function Expression
C) A Parameter
D) A Property
74. Function Declarations can be used before they are defined. This is because they
are:
A) Hoisted
B) Global
C) Recursive
D) Loops
75. Do arrow functions have their own this context? (Implied context based on
standard JS knowledge, though specific text says "shorter syntax introduced in ES6")
A) Yes
B) No
C) Sometimes
D) Only in loops
76. What is the output of function greet(name) { return 'Hello ' + name; }
greet('Alice');?
A) Hello
B) Alice
C) Hello Alice
D) undefined
Answers Part 6: 67: B | 68: C | 69: B | 70: C | 71: C | 72: B | 73: B | 74: A (Implicit in "can be
used before it's defined") | 75: B (General JS Knowledge/Hinted by "shorter syntax") | 76: C
Part 7: DOM Manipulation
77. What does DOM stand for?
A) Data Object Model
B) Document Object Model
C) Digital Order Manager
D) Document Orientation Method
78. The DOM allows JavaScript to:
A) Change the browser version
B) Interact with and manipulate HTML elements and styles
C) Write server-side SQL
D) Change the user's operating system
79. Which method selects an element by its unique ID?
A) getElementByClass
B) getElementById
C) querySelector
D) selectId
80. [Link]('.className') selects:
A) All elements with that class
B) The first element matching the class
C) An element with that ID
D) The body tag
81. To modify the text inside an element, you use:
A) textValue
B) content
C) textContent
D) writeText
82. Which property is used to insert HTML content directly?
A) innerText
B) outerHTML
C) innerHTML
D) htmlContent
83. How do you change the text color of an element el to red?
A) [Link] = 'red'
B) [Link] = 'red'
C) [Link] = 'red'
D) [Link]('red')
84. Which method is used to attach a function to a user action (like a click)?
A) attachEvent
B) onEvent
C) addEventListener
D) listen
85. In [Link]('click', callback), what is 'click'?
A) The function name
B) The event type
C) The element ID
D) The return value
86. [Link] returns:
A) A single element
B) An array-like collection of elements
C) A string
D) undefined
87. Which method selects elements by their tag name (e.g., <p>)?
A) getElementsByTagName
B) getTags
C) queryTag
D) selectTags
88. To capture user text from an input box with id input, you use:
A) [Link]('input').text
B) [Link]('input').value
C) [Link]('input').content
D) [Link]('input').innerHTML
Answers Part 7: 77: B | 78: B | 79: B | 80: B | 81: C | 82: C | 83: B | 84: C | 85: B | 86: B | 87:
A | 88: B
Part 8: Calculator Project & General Review
89. What is the role of [Link] in the calculator project?
A) Styling the calculator
B) Handling logic
C) Defining the structure (buttons & display)
D) Running the database
90. What is the role of [Link] in the project?
A) Calculations
B) Styling the layout
C) Structure
D) Events
91. Which JavaScript function is used in the calculator to evaluate the mathematical
expression?
A) calc()
B) math()
C) eval()
D) compute()
92. What event is listened for on the calculator buttons?
A) hover
B) click
C) submit
D) focus
93. What CSS property is used to make the calculator buttons arrange in a grid?
A) display: flex
B) display: grid
C) display: block
D) display: inline
94. In the calculator JavaScript, [Link] refers to:
A) The display screen
B) The value of the button that was clicked
C) The entire document
D) The window object
95. What does the "C" button do in the calculator project?
A) Calculates the result
B) Clears the display
C) Copies the result
D) Closes the app
96. If eval() encounters an invalid expression, what block catches the error?
A) if...else
B) try...catch
C) switch
D) for loop
97. What file extension is used for the stylesheet?
A) .html
B) .js
C) .css
D) .txt
98. [Link](".btn") returns:
A) Only the first button
B) All elements with the class "btn"
C) All button tags
D) The element with ID "btn"
99. Which data type is currentInput initialized as in the project?
A) Number (0)
B) String ("")
C) Array ([])
D) Boolean (false)
100. In the CSS, 100vh stands for:
A) 100 vertical hours
B) 100% of the viewport height
C) 100 virtual heights
D) 100 view headers
101. Which function converts the result of eval() to a string?
A) toText()
B) stringify()
C) toString()
D) convert()
102. What happens if you try to edit images of key political figures with the AI tool
mentioned in the system instructions?
A) It is allowed
B) It is constrained/not allowed
C) It requires a paid tier
D) It takes longer
Answers Part 8: 89: C | 90: B | 91: C | 92: B | 93: B | 94: B | 95: B | 96: B | 97: C | 98: B | 99:
B | 100: B (Standard CSS knowledge implied by use in ) | 101: C | 102: B (Derived from
System Instructions)