MCQ

JavaScript MCQs – Multiple Choice Questions and Answers – Part 5

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. Which of the following functions is a valid type of function that javascript supports?

A named function

B anonymous function

C Both A and B are true.

D None of the above

C
A function in JavaScript can be named or anonymous.
Here is a typical example of a named function:

function sayHello()
{
  alert("Hello World!");
}
sayHello();

Here is a typical example of an anonymous function:

var sayHello = function()
{
  alert("Hello World!");
}
sayHello();

 

 

2. Which method returns the character at the specified index?

A characterAt()

B getCharAt()

C charAt()

D None of the above

C
The charAt() method returns the character at the specified index. Example:

  var str = "StackHowTo";
  var res = str.charAt(0)      //S

 

 

3. Which of the following is not a mouse event?

A onmousescroller

B onclick

C onmouseover

D onmousemove

A

 

 

4. The opposite of onmouseover is_____?

A onmouseoff

B onmouseout

C onmouseunder

D onnotmouseover

B
The event onmouseover occurs when the mouse pointer is moved over an item or one of its sub-items.

The event onmouseout occurs when the mouse pointer is moved out of an element or over one of its sub-elements.

 

 

5. How to know the number of elements of a form?

A document.myform.elements.count

B document.myform.length

C document.myform.count

D document.myform.elements.length

D

 

 

6. Which method returns the string starting at the specified position?

A substr()

B getSubstring()

C slice()

D None of the above

A
The substr() method returns the string starting at the specified position by the specified number of characters. Example:

var s = "Hello world!";
var res = str.substr(1, 3);  //ell

 

 

7. The tag <noscript> will work __________________

A only with external scripts

B with internal and external scripts

C whether there is javascript or not

D only in browsers that don’t know what javascript is.

C
The tag <noscript> defines an alternate content for users who have scripting disabled in their browser or whose browser does not support scripting. Example of use:

<script>
     document.write("Welcome to StackHowTo!")
</script>
<noscript> Your browser does not support javascript! </noscript>

 

 

8. Browsers that do not understand Javascript _______

A ignore all tags <script> and <noscript>

B display the content of the tags <script>

C display the content of the tags <noscript>

D display the content of the tags <script> and <noscript>

C

 

 

9. Which of these contains an executable statement?

A // var x = 0; // var y = 0;

B /* var x = 0; // var y = 0; */

C /* var x = 0; */ var y = 0;

D // var x = 0; /* var y = 0; */

C

 

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 *