-
Notifications
You must be signed in to change notification settings - Fork 0
/
11.转换为number.html
46 lines (37 loc) · 1.27 KB
/
11.转换为number.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
37
38
39
40
41
42
43
44
45
46
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script>
/*
将其他的数据类型转换为Number
转换方式一:
使用Number()函数
- 字符串--> 数值
1.如果是纯数字的字符串,则直接将其转换为数字
2.如果字符串中有非数字的内容则转换为NaN
3.如果字符串是一个空串或者是一个全是空格的字符串,则转换为0
- 布尔值-->数值
true-->1
false-->0
- Null --> 数字0
- Undefined -->数字NaN
*/
var a="123";
//调用Number()函数来将a转换为Number类型
a=Number(a);
a=true;
a=Number(a);
a=null;
a=Number(a);
a=undefined;
a=Number(a);
console.log(typeof a);
console.log(a);
</script>
</head>
<body>
</body>
</html>