My Report

JavaScript Objects Test – 1


Correct Answer: 2 points | Wrong: -1 point
Grades: A* (100% score) | A (80%-99%) | B (60%-80%) | C (40%-60%) | D (0%-40%)
advertisement

1. What will happen if we call setTimeout() with a time of 0 ms?

2. To which object does the location property belong?

3. What will be the output of the following JavaScript code?

function counth2()
{  
    var totalh2=document.getElementsByTagName("h2");  
    alert("totalh2.length);  
}  
<h2>hello</h2>  
<h2>hello</h2> 

4. What is the result of the following code snippet?

window.location === document.location

5. The setTimeout() belongs to which object?

6. Which method receives the return value of setInterval() to cancel future invocations?

7. Which is the handler method used to invoke when uncaught JavaScript exceptions occur?

8. What will be the output of the following JavaScript code?

  
function totalelements()  
{  
    var allgenders=document.getElementsByName("gender");  
    alert("Total Genders:"+allgenders.length);  
}  
<form>  
     <input type="radio" name="gender" value="male">  
     <input type="radio" name="gender" value="female">  
     <input type="button" onclick="totalelements()" value="Total Genders">  
</form>  

9. Which property is used to obtain browser vendor and version information?

10. Which method receives the return value of setTimeout() to cancel future invocations?

11. What will be the output of the following JavaScript code?

function validate() 
{  
    var msg;  
    if(document.myForm.userPass.value.length>5)
    {  
        msg="good";  
    }  
    else
    {  
         msg="poor";  
    }  
    document.getElementById('mylocation').innerText=msg;  
}  
<form name="myForm">  
<input type="password" value="rhuld"  onkeyup="validate()">  
Strength:<span id="mylocation">no strength</span>  
</form>  

12. What will be the output of the following JavaScript code?

function showcommentform() 
{  
    var data=”new text”  
    document.getElementById('mylocation').innerHTML=data;  
}  
<form name="myForm">  
<input type="button" value="comment" onclick="showcommentform()">  
<div id="mylocation"></div> 
</form>

13. Which function among the following lets to register a function to be invoked once?

14. Which function among the following lets to register a function to be invoked repeatedly after a certain time?

15. What will be the output of the following JavaScript code?

function getcube()
{  
    var number=document.getElementById("number").value;  
    alert(number*number*number);  
}
<form>  
     Enter No:<input type="text" id="number" value="3" name="number"/><br/>  
     <input type="button"  value="ok" onclick="getcube()"/>  
</form>

 

Start practicing “1000 MCQs on JavaScript”, and once you are ready, you can take tests on all topics by attempting our “JavaScript Test Series”.

Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.