HTML and CSS Reference
In-Depth Information
EXAMPLE
parseInt("111", 2); 7 ( 111 in base 2 is 7)
parseInt("45days"); 45
Table 5.16 parseInt(String)
String
Result
"hello"
NaN
"Route 66"
NaN
"6 dogs"
6
"6"
6
"-6"
-6
"6.56"
6
"0Xa"
10
"011"
9
Table 5.17 parseInt(String, NumberBase)
String
Base
Result (Decimal)
"111"
2 (binary)
7
"12"
8 (octal)
10
"b"
16 (hex)
11
EXAMPLE 5.15
<html>
<head><title>Using the parseInt() Function</title></head>
<body><font face="arial size="+1">
<b>
<script type= "text/javascript">
1
var grade = prompt("What is your grade? ", "");
// Grade entered as a string
2
grade=parseInt(grade);
// Grade converted to an integer
3
document.write("grade type is<em> " + typeof(grade)) ;
4
grade+=10;
Continues
Search WWH ::




Custom Search