Set - 6

Question 11 :

How to reload the current page ?

Answer :

window.location.reload(true);


Question 12 :

how to force a page to go to another page using JavaScript ?

Answer :

<script language="JavaScript" type="text/javascript" ><!-- location.href="http://newhost/newpath/newfile.html"; //--></script>


Question 13 :

How to convert a string to a number using JavaScript?

Answer :

You can use the parseInt() and parseFloat() methods. Notice that extra letters following a valid number are ignored, which is kinda wierd but convenient at times.

parseInt("100") ==> 100
parseFloat("98.6") ==> 98.6
parseFloat("98.6 is a common temperature.") ==> 98.6
parseInt("aa") ==> Nan //Not a Number
parseInt("aa",16) ==> 170 //you can supply a radix or base


Question 14 :

How to convert numbers to strings using JavaScript? 

Answer :

You can prepend the number with an empty string 
var mystring = ""+myinteger; 
or 
var mystring = myinteger.toString(); 
You can specify a base for the conversion, 
var myinteger = 14; 
var mystring = myinteger.toString(16);

mystring will be "e".


Question 15 :

How to test for bad numbers using JavaScript? 

Answer :

the global method, "isNaN()" can tell if a number has gone bad.

var temperature = parseFloat(myTemperatureWidget.value);
if(!isNaN(temperature)) {
    alert("Please enter a valid temperature.");
}