JavaScript Objective Questions and Answers Module -2


11.How do you convert numbers between different bases in JavaScript? 
Use the parseInt() function, that takes a string as the first parameter, and the base as a second parameter. So to convert hexadecimal FF to decimal, use parseInt ("FF", 16);

12.What is negative infinity? 
It’s a number in JavaScript, derived by dividing negative number by zero.

13.How to set a HTML document's background color? 
document.bgcolor property can be set to any appropriate color.

14.What boolean operators does JavaScript support?
&&, and !

15.How to get the contents of an input box using Javascript? 
Use the "value" property.
var myValue = window.document.getElementById("textboxID").value;

16.How to determine the state of a checkbox using Javascript? 
var checkedP = window.document.getElementById("CheckBoxID").checked;

17.How to set the focus in an element using Javascript? 
<script> function setFocus() { if(focusElement != null) { document.forms[0].elements["myelementname"].focus(); } } </script>

18.How to access an external javascript file that is stored externally and not embedded? 
This can be achieved by using the following tag between head tags or between body tags.
<script src="raj.js"></script>How to access an external javascript file that is stored externally and not embedded? where abc.js is the external javascript file to be accessed.

19.What is the difference between an alert box and a confirmation box? 
An alert box displays only one button which is the OK button whereas the Confirm box displays two buttons namely OK and cancel.

20.What is a prompt box? 

A prompt box allows the user to enter input by providing a text box.

No comments:

Post a Comment