Unit 2 - Practice Quiz

INT219 50 Questions
0 Correct 0 Wrong 50 Left
0/50

1 Which of the following is the correct syntax for a single-line comment in JavaScript?

A. <!-- This is a comment -->
B. / This is a comment /
C. // This is a comment
D. # This is a comment

2 What is the result of the following expression: typeof null?

A. "null"
B. "undefined"
C. "object"
D. "number"

3 Which keyword is used to declare a variable that cannot be reassigned?

A. var
B. let
C. const
D. static

4 What is the output of the code console.log(3 + "3");?

A. 6
B. "33"
C. 33
D. TypeError

5 Which operator is used to calculate the remainder of a division, represented mathematically as ?

A. /
B. %
C. &
D. #

6 What is the correct way to write an array in JavaScript?

A. var colors = "red", "green", "blue"
B. var colors = (1:"red", 2:"green", 3:"blue")
C. var colors = ["red", "green", "blue"]
D. var colors = {"red", "green", "blue"}

7 What is the output of 2 ** 3 in JavaScript?

A. 5
B. 6
C. 8
D. 9

8 Which of the following creates a function using Arrow syntax?

A. function myFunction() {}
B. const myFunction = function() {}
C. const myFunction = () => {}
D. func myFunction = () -> {}

9 Which method is used to remove the last element from an array?

A. shift()
B. pop()
C. push()
D. remove()

10 What applies to the scope of a variable declared with var?

A. It is always block-scoped.
B. It is function-scoped or globally scoped.
C. It is only available inside if statements.
D. It cannot be hoisted.

11 How do you access the value of the property name in the object user?

A. user[name]
B. user.name
C. user(name)
D. user->name

12 Which comparison operator checks for both value and type (Strict Equality)?

A. =
B. ==
C. ===
D. !=

13 What is the result of Boolean("")?

A. true
B. false
C. undefined
D. null

14 Which method attaches an event handler to an HTML element?

A. attachEvent()
B. on()
C. addEventListener()
D. listen()

15 How do you write an if statement that executes code if i is NOT equal to 5?

A. if i <> 5
B. if (i != 5)
C. if (i =! 5)
D. if i != 5 then

16 What is the correct syntax for referring to an external script called app.js?

A. <script href="app.js">
B. <script src="app.js">
C. <script name="app.js">
D. <link src="app.js">

17 Which of the following is NOT a JavaScript data type?

A. Number
B. Boolean
C. Float
D. Undefined

18 What keyword allows you to return a value from a function?

A. send
B. return
C. output
D. break

19 In the DOM, which object represents the browser window?

A. document
B. body
C. window
D. browser

20 How does a while loop differ from a do...while loop?

A. A while loop runs at least once.
B. A do...while loop checks the condition before the block.
C. A do...while loop runs the block at least once before checking the condition.
D. There is no difference.

21 What is the purpose of the this keyword?

A. It refers to the current function.
B. It refers to the object from which the function was called.
C. It refers to the global variable scope.
D. It refers to the previous variable used.

22 Which statement correctly creates a constant array?

A. const cars = ["Saab", "Volvo", "BMW"];
B. constant cars = ["Saab", "Volvo", "BMW"];
C. let const cars = ["Saab", "Volvo", "BMW"];
D. cars = const ["Saab", "Volvo", "BMW"];

23 What logic does the operator || represent?

A. Logical AND
B. Logical OR
C. Logical NOT
D. Bitwise OR

24 How do you check the length of an array named tasks?

A. tasks.length
B. tasks.size()
C. tasks.count
D. tasks.length()

25 Which method is used to convert a JSON string into a JavaScript object?

A. JSON.stringify()
B. JSON.parse()
C. JSON.toObject()
D. JSON.convert()

26 What is the output of console.log(10 == "10")?

A. true
B. false
C. undefined
D. NaN

27 Which event occurs when a user clicks on an HTML element?

A. onchange
B. onmouseover
C. onclick
D. onmouseclick

28 What is the correct way to select an HTML element by its ID?

A. document.selectId("myId")
B. document.getElementById("myId")
C. document.querySelector("myId")
D. window.getId("myId")

29 Which statement stops the execution of a loop but allows the loop to continue with the next iteration?

A. stop
B. break
C. exit
D. continue

30 Which variable declaration is hoisted to the top of its scope and initialized with undefined?

A. let
B. const
C. var
D. func

31 What does isNaN() function check?

A. If a value is null
B. If a value is a number
C. If a value is Not-a-Number
D. If a value is infinite

32 What syntax allows you to unpack values from arrays into distinct variables?

A. Hoisting
B. Destructuring
C. Spread operator
D. Literal Syntax

33 What is the result of "Hello".charAt(0)?

A. "e"
B. "H"
C. "Hello"
D. 0

34 Which operator is used for the logical NOT operation?

A. !
B. |
C. &
D. ~

35 What is the correct syntax for a switch statement?

A. switch (expression) { case x: code block; break; }
B. switch { case x: code block; break; }
C. switch (expression) { case x -> code block; }
D. case (expression) { switch x: code block; }

36 Which array method creates a new array by performing a function on each array element?

A. forEach()
B. map()
C. filter()
D. every()

37 What is the value of x after: let x = 5; x += 3;?

A. 5
B. 3
C. 8
D. 53

38 Which of the following is true about arrow functions and the this keyword?

A. Arrow functions have their own this binding.
B. Arrow functions inherit this from the parent scope.
C. Arrow functions cannot use this.
D. this in arrow functions always refers to the window.

39 To prevent a form from submitting when a button is clicked, which method is used on the event object?

A. event.stop()
B. event.halt()
C. event.preventDefault()
D. event.stopPropagation()

40 Which popup box displays a message and returns true (OK) or false (Cancel)?

A. alert()
B. prompt()
C. confirm()
D. message()

41 If var a = [1, 2, 3];, what is a[3]?

A. 3
B. 2
C. undefined
D. null

42 Which of the following is a Template Literal?

A. "Hello World"
B. 'Hello World'
C. Hello World
D. (Hello World)

43 What does the push() method return?

A. The new array
B. The new length of the array
C. The element that was added
D. undefined

44 What is the global scope in a browser environment?

A. The HTML file
B. The document object
C. The window object
D. The console object

45 Which method is used to write HTML expressions or JavaScript code to a document?

A. window.print()
B. document.write()
C. console.log()
D. innerHTML

46 What happens if you define a variable without var, let, or const in strict mode?

A. It becomes a global variable.
B. It becomes a local variable.
C. It throws a ReferenceError.
D. It creates a constant.

47 Which logical operator has the highest precedence?

A. || (OR)
B. && (AND)
C. ! (NOT)
D. They have equal precedence

48 How do you define a default parameter in a function?

A. function myFunc(x = 10) { }
B. function myFunc(x : 10) { }
C. function myFunc(x default 10) { }
D. function myFunc(x) { x = 10; }

49 What property replaces the content of an HTML element, parsing the new content as HTML?

A. innerText
B. textContent
C. innerHTML
D. value

50 Which of these is a valid ternary operator expression?

A. condition ? expr1 : expr2
B. condition : expr1 ? expr2
C. condition ? expr1 ? expr2
D. condition ?? expr1 : expr2