Computer Science Exam MCQs - Part 4

10 multiple-choice questions (MCQs) on JavaScript


31) What is JavaScript?

A) A programming language for creating dynamic web pages

B) A markup language for styling web pages

C) A database management system

D) A descendant language from Java



32) Which keyword is used to declare a variable in JavaScript?

A) var

B) let

C) const

D) All of the above



33) What does the typeof operator return when applied to an array?

A) "array"

B) "object"

C) "array"

D) "undefined"



34) Which of the following is not a valid way to declare a function in JavaScript?

A) function myFunction() {}

B) var myFunction = function() {}

C) const myFunction = () => {}

D) let myFunction() {}



35) What does the === operator do in JavaScript?

A) Checks for equality without type conversion

B) Checks for equality with type conversion

C) Assigns a value to a variable

D) None of the above



36) Which method is used to add an element to the end of an array?

A) push()

B) pop()

C) shift()

D) unshift()



37) What is the purpose of the querySelector() method in JavaScript?

A) To select an element based on its class name

B) To select an element based on its ID

C) To select the first element that matches a CSS selector

D) To select all elements that match a CSS selector



38) Which event occurs when the user clicks on an HTML element?

A) onchange

B) onclick

C) onmouseover

D) onload



39) What does the setTimeout() function do in JavaScript?

A) Executes a function repeatedly at a fixed interval

B) Executes a function after a specified delay

C) Stops the execution of a function

D) None of the above



40) What does the console.log() method do in JavaScript?

A) Displays a message in the browser's console

B) Creates a popup window with a message

C) Adds a message to the web page

D) None of the above



--- Continued



Answer Keys

31- A) A programming language for creating dynamic web pages

32- D) All of the above

33- B) "object"

34- D) let myFunction() {}

35- A) Checks for equality without type conversion

36- A) push()

37- C) To select the first element that matches a CSS selector

38- B) onclick

39- B) Executes a function after a specified delay

40- A) Displays a message in the browser's console 

Comments

Popular posts from this blog

Quotation marks to wrap an element in HTML

The Basic Structure of a Full-Stack Web App

Unlocking Web Design: A Guide to Mastering CSS Layout Modes