-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathUndefinedVsNull.js
64 lines (52 loc) · 1.45 KB
/
UndefinedVsNull.js
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
//-------------------------------------------------------------------------------------------------------
// Copyright (C) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
//-------------------------------------------------------------------------------------------------------
//
// Test Equals operator with abstract equality comparison algorithm (ES3.0: S11.9.1, S11.9.3)
//
if (undefined == null)
WScript.Echo("Algorithm says equivalent");
else
WScript.Echo("Objects are not equivalent");
//
// Test Strict Equals operator (ES3.0: S11.9.4)
//
if (undefined === null)
WScript.Echo("Same instance");
else
WScript.Echo("Different instances");
if (undefined === undefined)
WScript.Echo("Same instance");
else
WScript.Echo("Different instances");
if (null === null)
WScript.Echo("Same instance");
else
WScript.Echo("Different instances");
function dump(a, index)
{
var value = a[index];
if (value === undefined)
{
WScript.Echo("'undefined'");
}
else if (value === null)
{
WScript.Echo("'null'");
}
else
{
WScript.Echo(value);
}
}
//
// Create an array and grow it, ensuring that all empty slots are properly set to 'undefined'
//
var a = new Array(2);
dump(a, 0);
dump(a, 1);
dump(a, 10);
a[10] = 'A';
dump(a, 10);
dump(a, 5);