forked from chuanxshi/javascript-patterns
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparseint.html
36 lines (30 loc) · 951 Bytes
/
parseint.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<!doctype html>
<html lang="en">
<head>
<title>JavaScript Patterns</title>
<meta charset="utf-8">
</head>
<body>
<script>
/* Title: Number Conversions with parseInt()
Description: use the second radix parameter
*/
// pattern 1
/* NOTE: in this example, if you omit the radix parameter like parseInt(year), the returned value will be 0,
* because "09" assumes octal number (as if you did parseInt( year, 8 )) and 09 is not a valid digit in base 8.
*/
var month = "06",
year = "09";
month = parseInt(month, 10);
year = parseInt(year, 10);
// pattern 2
/* NOTE: if you're expecting input such as “08 hello”, parseInt() will return a number, whereas the others will fail
* with NaN.
*/
+"08" // result is 8
Number("08") // 8
// References
// http://net.tutsplus.com/tutorials/javascript-ajax/the-essentials-of-writing-high-quality-javascript/
</script>
</body>
</html>