356). Which function among the following lets to register a function to be invoked once?
[A]setTimeout()
[B]setTotaltime()
[C]setInterval()
[D]settime()
Show Answer
Correct Answer: setTimeout()
Notes:
Answer: a
Explanation: setTimeout() and setInterval() allow you to register a function to be invoked once or repeatedly after a specified amount of time has elapsed. Both these function are used to do time manipulation in javascript.
357). Which function among the following lets to register a function to be invoked repeatedly after a certain time?
[A]setTimeout()
[B]setTotaltime()
[C]setInterval()
[D] settime()
Show Answer
Correct Answer: setInterval()
Notes:
Answer: c
Explanation: setTimeout() and setInterval() allow you to register a function to be invoked once or repeatedly after a specified amount of time has elapsed. Both these function are used to do time manipulation in javascript.
358). Which is the handler method used to invoke when uncaught JavaScript exceptions occur?
[A]Onhalt
[B]Onerror
[C]Both onhalt and onerror
[D]Onsuspend
Show Answer
Correct Answer: Onerror
Notes:
Answer: b
Explanation: The onerror handler method can be registered to be invoked when uncaught JavaScript exceptions occur. The onerror event is triggered if an error occurs while loading an external file (e.g. a document or an image).
359). Which property is used to obtain browser vendor and version information?
[A]modal
[B]version
[C]browser
[D]navigator
Show Answer
Correct Answer: navigator
Notes:
Answer: d
Explanation: The navigator property is used to obtain browser vendor and version information. Various navaigator property includes appname, appversion, geolocation, language etc.
360). Which method receives the return value of setInterval() to cancel future invocations?
[A]clearInvocation()
[B]cancelInvocation()
[C]clearInterval()
[D]clear()
Show Answer
Correct Answer: clearInterval()
Notes:
Answer: c
Explanation: Like setTimeout(), setInterval() returns a value that can be passed to clearInterval() to cancel any future invocations of the scheduled function. The ID value returned by setInterval() is used as the parameter for the clearInterval() method.
361). The setTimeout() belongs to which object?
[A]Element
[B]Window
[C]Location
[D]Event
Show Answer
Correct Answer: Window
Notes:
Answer: b
Explanation: The setTimeout() method of the Window object schedules a function to run after a specified number of milliseconds elapses. setTimeout() and setInterval() are used for time manipulations in javascript.
362). Which method receives the return value of setTimeout() to cancel future invocations?
[A]clearTimeout()
[B]clearInterval()
[C]clearSchedule()
[D]cancelInvocation()
Show Answer
Correct Answer: clearTimeout()
Notes:
Answer: a
Explanation: setTimeout() returns a value that can be passed to clearTimeout() to cancel the execution of the scheduled function. The ID value returned by setTimeout() is used as the parameter for the clearTimeout() method.
363). What will happen if we call setTimeout() with a time of 0 ms?
[A]Placed in stack
[B]Placed in queue
[C]Will run continuously
[D]Will execute immediately
Show Answer
Correct Answer: Placed in queue
Notes:
Answer: b
Explanation: If you call setTimeout() with a time of 0 ms, the function you specify is not invoked right away. Instead, it is placed on a queue to be invoked “as soon as possible” after any currently pending event handlers finish running.
364). To which object does the location property belong?
[A]Window
[B]Position
[C]Element
[D]Location
Show Answer
Correct Answer: Window
Notes:
Answer: a
Explanation: The location property of the Window object refers to a Location object, which represents the current URL of the document displayed in the window. The window.location object can be used to get the current page address (URL) and to redirect the browser to a new page.
365). What is the result of the following code snippet?
window.location === document.location
[A]False
[B]True
[C]0
[D]1
Show Answer
Correct Answer: True
Notes:
Answer: b
Explanation: The window.location object can be used to get the current page address (URL) and to redirect the browser to a new page. The Document.location read-only property returns a Location object, which contains information about the URL of the document and provides methods for changing that URL and loading another URL.
366). What will be the output of the following JavaScript code?
function getcube()
{
var number=document.getElementById("number").value;
alert(number*number*number);
}
[A]9
[B]27
[C]Error
[D]Undefined
Show Answer
Correct Answer: 27
Notes:
Answer: b
Explanation: The document.getElementById() is used to get value of the input text. But we need to define id for the input field.
367). What will be the output of the following JavaScript code?
function totalelements()
{
var allgenders=document.getElementsByName("gender");
alert("Total Genders:"+allgenders.length);
}
Show Answer
Correct Answer: 2
Notes:
Answer: c
Explanation: The document.getElementsByName() method returns all the element of specified name. The above code counts the total number of output mentioned in the form.
368). What will be the output of the following JavaScript code?
function counth2()
{
var totalh2=document.getElementsByTagName("h2");
alert("totalh2.length);
}
hello
hello
Show Answer
Correct Answer: 2
Notes:
Answer: d
Explanation: The document.getElementsByTagName() method returns all the element of specified tag name. The above code counts the total number of specific tags.
369). 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;
}
[A]Strength: good
[B]Strength: poor
[C]Strength: no strength
[D]Undefined
Show Answer
Correct Answer: Strength: poor
Notes:
Answer: b
Explanation: The innerText property can be used to write the dynamic text on the html document. It is used mostly in the web pages to generate dynamic content such as writing the validation message, password strength etc.
370). What will be the output of the following JavaScript code?
function showcommentform()
{
var data=”new text”
document.getElementById('mylocation').innerHTML=data;
}
[A]Comment
[B]new text
[C]Error
[D]Undefined
Show Answer
Correct Answer: Comment
Notes:
Answer: a
Explanation: The innerHTML property can be used to write the dynamic html on the html document. It is used mostly in the web pages to generate dynamic html such as registration form, comment form, links etc.