-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.html
97 lines (88 loc) · 3.38 KB
/
test.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<!DOCTYPE HTML>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<title></title>
<link href="//netdna.bootstrapcdn.com/twitter-bootstrap/2.1.1/css/bootstrap.min.css" rel="stylesheet">
<style type="text/css">
.content {
width: 600px;
text-align: center;
margin: 10px auto;
}
.table {
width: 100%;
}
.table th, .table td {
text-align: center;
}
</style>
</head>
<body>
<div class="content">
<h1>Javascript Type Tests</h1>
<script type="text/javascript">
var test = {},
testValues = [null,
NaN,
true,
false,
-1,
0,
1,
'0',
'',
function() {},
function() { return a; },
function(a, b) { return a + b; },
{},
[],
['foo', 'bar']
],
testStrings = ['null',
'NaN',
'true',
'false',
'-1',
'0',
'1',
'\'0\'',
'\'\'',
'function() { }',
'function() { <br />return a;<br />}',
'function(a, b) {<br />return a + b;<br />}',
'{ }',
'[ ]',
'[\'foo\', \'bar\']'
];
document.write('<table class="table striped bordered"><tr><th>Value</th><th>Type</th><th>if() result</th><th>length property</th><th>length</th></tr>');
document.write('<tr><td>' + test.test + '</td><td>' + typeof(test.test) + '</td><td>');
if (test.test) {
document.write('<span class="label success small">true</span>');
} else {
document.write('<span class="label error small">false</span>');
}
if (test.test !== undefined && test.test.length !== undefined) {
document.write('</td><td><span class="label success small">true</span></td><td><span class="">' + test.test.length + '</span></td></tr>');
} else {
document.write('</td><td><span class="label error small">false</span></td><td></td></tr>');
}
testValues.forEach(function(value, index) {
test.test = value;
document.write('<tr><td>' + testStrings[index] + '</td><td>' + typeof(test.test) + '</td><td>');
if (test.test) {
document.write('<span class="label success small">true</span>');
} else {
document.write('<span class="label error small">false</span>');
}
if (test.test !== null && test.test.length !== undefined) {
document.write('</td><td><span class="label success small">true</span></td><td><span class="">' + test.test.length + '</span></td></tr>');
} else {
document.write('</td><td><span class="label error small">false</span></td><td></td></tr>');
}
});
document.write('</table>');
</script>
</div>
</body>
</html>