0% found this document useful (0 votes)
9 views5 pages

Chapter 4

The document contains a series of multiple-choice questions (MCQs) focused on JavaScript concepts, including its usage, syntax, functions, and methods. Each question is accompanied by the correct answer, covering topics such as variable declaration, event handling, and data manipulation. The content serves as a quiz or study guide for individuals looking to test or enhance their JavaScript knowledge.

Uploaded by

ravi500shinde
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views5 pages

Chapter 4

The document contains a series of multiple-choice questions (MCQs) focused on JavaScript concepts, including its usage, syntax, functions, and methods. Each question is accompanied by the correct answer, covering topics such as variable declaration, event handling, and data manipulation. The content serves as a quiz or study guide for individuals looking to test or enhance their JavaScript knowledge.

Uploaded by

ravi500shinde
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 5

MCQ 1:

Question: What is JavaScript primarily used for?

A) Styling web pages


B) Adding interactivity to web pages
C) Creating databases
D) Managing server-side operations
Answer: B) Adding interactivity to web pages

MCQ 2:
Question: Where is JavaScript code typically executed?

A) On the server
B) In the user's browser
C) In the database
D) On a mobile app
Answer: B) In the user's browser

MCQ 3:
Question: Which tag is used to include external JavaScript files in HTML?

A) <script>
B) <link>
C) <style>
D) <js>
Answer: A) <script>

MCQ 4:
Question: What is the purpose of the document.write() function in JavaScript?

A) To read data from a file


B) To write content to the web page
C) To execute a SQL query
D) To create a new HTML element
Answer: B) To write content to the web page

MCQ 5:
Question: How do you declare a variable in JavaScript?

A) var variableName;
B) let variableName;
C) const variableName;
D) All of the above
Answer: D) All of the above

MCQ 6:
Question: What is the purpose of the console.log() function in JavaScript?

A) To display messages in the browser's console


B) To execute a function
C) To create a new variable
D) To style an HTML element
Answer: A) To display messages in the browser's console

MCQ 7:
Question: Which operator is used to assign a value to a variable in JavaScript?

A) =
B) ==
C) ===
D) !=
Answer: A) =

MCQ 8:
Question: What does the typeof operator return in JavaScript?

A) The type of the operand


B) The value of the operand
C) The size of the operand
D) The location of the operand
Answer: A) The type of the operand

MCQ 9:
Question: Which loop is used for iterating over the properties of an object in
JavaScript?

A) for loop
B) for...in loop
C) while loop
D) do...while loop
Answer: B) for...in loop

MCQ 10:
Question: What is the purpose of the addEventListener() method in JavaScript?

A) To remove an event listener


B) To attach an event handler to an element
C) To execute a function immediately
D) To create a new HTML element
Answer: B) To attach an event handler to an element

MCQ 11:
Question: How do you create a function in JavaScript?

A) function myFunction() { ... }


B) def myFunction() { ... }
C) myFunction() { ... }
D) createFunction myFunction() { ... }
Answer: A) function myFunction() { ... }

MCQ 12:
Question: What is the purpose of the return statement in a JavaScript function?

A) To end the function execution


B) To return a value from the function
C) To call another function
D) To define a variable
Answer: B) To return a value from the function

MCQ 13:
Question: Which method is used to access elements by their ID in JavaScript?

A) getElementById()
B) querySelector()
C) getElementsByClassName()
D) getElementsByTagName()
Answer: A) getElementById()
MCQ 14:
Question: What is the purpose of the this keyword in JavaScript?

A) To refer to the current object


B) To define a new variable
C) To execute a function
D) To create a new HTML element
Answer: A) To refer to the current object

MCQ 15:
Question: How do you create an array in JavaScript?

A) var myArray = [];


B) var myArray = {};
C) var myArray = new Array();
D) All of the above
Answer: D) All of the above

MCQ 16:
Question: Which method is used to add an element to the end of an array in
JavaScript?

A) push()
B) pop()
C) shift()
D) unshift()
Answer: A) push()

MCQ 17:
Question: What is the purpose of the JSON.parse() method in JavaScript?

A) To convert a JSON string into a JavaScript object


B) To convert a JavaScript object into a JSON string
C) To execute a function
D) To create a new HTML element
Answer: A) To convert a JSON string into a JavaScript object

MCQ 18:
Question: Which event occurs when the user clicks on an HTML element?

A) onmouseover
B) onclick
C) onload
D) onsubmit
Answer: B) onclick

MCQ 19:
Question: What is the purpose of the preventDefault() method in JavaScript?

A) To prevent the default action of an event


B) To execute a function
C) To create a new HTML element
D) To define a variable
Answer: A) To prevent the default action of an event

MCQ 20:
Question: How do you create a new object in JavaScript?

A) var obj = {};


B) var obj = new Object();
C) var obj = [];
D) Both A and B
Answer: D) Both A and B

MCQ 21:
Question: Which method is used to remove the last element from an array in
JavaScript?

A) pop()
B) push()
C) shift()
D) unshift()
Answer: A) pop()

MCQ 22:
Question: What is the purpose of the Math.random() function in JavaScript?

A) To generate a random number


B) To execute a function
C) To create a new HTML element
D) To define a variable
Answer: A) To generate a random number

MCQ 23:
Question: How do you check if a variable is an array in JavaScript?

A) Array.isArray(variable)
B) typeof variable === 'array'
C) variable instanceof Array
D) Both A and C
Answer: D) Both A and C

MCQ 24:
Question: Which method is used to convert all the characters in a string to
uppercase in JavaScript?

A) toUpperCase()
B) toLowerCase()
C) charAt()
D) substr()
Answer: A) toUpperCase()

MCQ 25:
Question: What is the purpose of the setInterval() function in JavaScript?

A) To execute a function repeatedly at specified intervals


B) To execute a function once after a delay
C) To create a new HTML element
D) To define a variable
Answer: A) To execute a function repeatedly at specified intervals

MCQ 26:
Question: Which method is used to remove the first element from an array in
JavaScript?

A) shift()
B) unshift()
C) pop()
D) push()
Answer: A) shift()

MCQ 27:
Question: What is the purpose of the localStorage object in JavaScript?

A) To store data locally in the browser


B) To execute a function
C) To create a new HTML element
D) To define a variable
Answer: A) To store data locally in the browser

MCQ 28:
Question: How do you create a promise in JavaScript?

A) new Promise((resolve, reject) => { ... })


B) new Promise()
C) Promise.create((resolve, reject) => { ... })
D) createPromise((resolve, reject) => { ... })
Answer: A) new Promise((resolve, reject) => { ... })

MCQ 29:
Question: Which method is used to convert a string to an integer in JavaScript?

A) parseInt()
B) parseFloat()
C) toString()
D) Number()
Answer: A) parseInt()

MCQ 30:
Question: What is the purpose of the fetch() function in JavaScript?

A) To make HTTP requests


B) To execute a function
C) To create a new HTML element
D) To define a variable
Answer: A) To make HTTP requests

You might also like