MCQ

JavaScript MCQs – Multiple Choice Questions and Answers – Part 6

Multiple choice questions and answers (MCQs) on JavaScript to prepare for exams, tests, and certifications. These questions are taken from a real written exam and some parts are taken from an interview. So you will find questions on basic techniques such as variables, functions, loops, objects, and more. This quiz will easily prepare anyone to pass their online test.
 

1. To know the identifier of the user’s OS, we use ______?

A navigator.userAgent

B navigator.system

C navigator.platform

D navigator.os

C
“navigator.platform” returns the user’s operating system. In the example below, we check if it is Windows 32 bits:

if(navigator.platform == “Win32”){
   //Code for windows 32 bits
}

 

 

2. Which of the following functions of “Number” object returns a string of the current number?

A toString()

B toFixed()

C toLocaleString()

D toPrecision()

A
toString() – This function converts a number into a string. Example:

var num= 5;
document.write("Output: " + num.toString());    //Output: 5

 

 

3. Which of the following functions of “String” object divides a String object into an array of strings by separating the string into substrings?

A slice()

B split()

C replace()

D search()

B
split() – Splits a String object into an array of strings by splitting the string into substrings. Example:

var str = "Hello world!";
var res = str.split(" "); //Hello,world!

 

 

4. Which of the following functions sorts the elements of an array?

A toSource()

B sort()

C toString()

D unshift()

B
sort() – Sorts the elements of an array. Example:

var letters = ['D', 'C', 'B', 'A'];
letters.sort();  //A B C D

 

 

5. When we can’t trigger JavaScript from an event handler?

A when another event is still being processed

B when Javascript is disabled

C when the page uses CSS styles

D when it runs locally rather than on the Web

B

 

 

6. Which of the following is the minimum browser version that supports JavaScript?

A Browser V1.0

B Mozilla V1.5

C IE 2.0

D Browser v2.0

D

 

 

7. You are working on a JavaScript project. Which of the following statements correctly describes the relationship between JavaScript and “objects”?

A JavaScript is object oriented

B JavaScript is object-based

C JavaScript is not an object oriented

D JavaScript has no relation to objects

B

 

 

8. You are working on a JavaScript project. How do I request inputs from the user?

A Alert()

B Display()

C Prompt()

D Confirm()

C
Example:

var food = prompt ("What is your favorite color?");

 

 

9. You are a junior web designer. Your company assigns you to work on a JavaScript project. What are the benefits of using JavaScript for form validation?

A Increase end-user satisfaction

B Increase the validity of form submission

C Conservation of bandwidth

D All the answers are true

D

 

 

10. Your company assigns you to work on a JavaScript project. With the DATE object, which of the following allows you to call a function based on the elapsed time?

A setElapsedTime()

B Timeout()

C setTimeout()

D setTime()

D

 

mcqMCQPractice competitive and technical Multiple Choice Questions and Answers (MCQs) with simple and logical explanations to prepare for tests and interviews.Read More

Leave a Reply

Your email address will not be published. Required fields are marked *