1
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2
<html xmlns="http://www.w3.org/1999/xhtml">
3
<head>
4
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5
<title>Undefined類型</title>
6
<script type="text/javascript">
7
/*
8
* 項目: book -> Javascript高級程序設計.pdf -> 第2章 -> 2.6.2 2.6 原始類型
9
*
10
* 說明: Undefined類型只有一個值,即undefined。當聲明的變量未初始時,該變量的默認值是undefined。
11
*
12
*
13
* 練習者: Alex刺客
14
*
15
* 日期: 2009-12-13
16
*/
17
var oTemp;
18
//判斷此變量類型的字面量是否等于undefined
19
alert(oTemp == undefined);
20
//true
21
22
//彈出此此變量的類型
23
alert("未初始化的變量 oTemp="+typeof oTemp);
24
//undefined
25
26
//注意: Alex變量未聲明此時彈出的也是undefined
27
alert("未聲明的變量 Alex="+typeof Alex);
28
29
//函數無明確返回值時,返回的也是undefined
30
function textMethod(){
31
32
}
33
alert("函數的返回值 textMethod()="+ textMethod());
34
35
</script>
36
</head>
37
<body>
38
</body>
39
</html>

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
