@@ -6,9 +6,9 @@ Everything in JavaScript acts like an object, with the only two exceptions being
6
6
false.toString(); // 'false'
7
7
[1, 2, 3].toString(); // '1,2,3'
8
8
9
- function Foo (){}
10
- Foo .bar = 1;
11
- Foo .bar; // 1
9
+ function sayHello (){}
10
+ sayHello .bar = 1;
11
+ sayHello .bar; // 1
12
12
13
13
A common misconception is that number literals cannot be used as
14
14
objects. That is because a flaw in JavaScript's parser tries to parse the * dot
@@ -32,25 +32,25 @@ Using an object literal - `{}` notation - it is possible to create a
32
32
plain object. This new object [ inherits] ( #object.prototype ) from ` Object.prototype ` and
33
33
does not have [ own properties] ( #object.hasownproperty ) defined.
34
34
35
- var foo = {}; // a new empty object
35
+ var names = {}; // a new empty object
36
36
37
- // a new object with a 'test ' property with value 12
38
- var bar = {test: 12 };
37
+ // a new object with a 'name ' property with value 'Rob'
38
+ var rob = {name: 'Rob' };
39
39
40
40
### Accessing Properties
41
41
42
42
The properties of an object can be accessed in two ways, via either the dot
43
43
notation or the square bracket notation.
44
44
45
- var foo = {name: 'kitten'}
46
- foo .name; // kitten
47
- foo [ 'name'] ; // kitten
45
+ var pet = {name: 'kitten'}
46
+ pet .name; // kitten
47
+ pet [ 'name'] ; // kitten
48
48
49
49
var get = 'name';
50
- foo [ get] ; // kitten
50
+ pet [ get] ; // kitten
51
51
52
- foo .1234; // SyntaxError
53
- foo [ '1234'] ; // works
52
+ pet .1234; // SyntaxError
53
+ pet [ '1234'] ; // works
54
54
55
55
The notations work almost identically, with the only difference being that the
56
56
square bracket notation allows for dynamic setting of properties and
@@ -63,21 +63,21 @@ operator; setting the property to `undefined` or `null` only removes the
63
63
* value* associated with the property, but not the * key* .
64
64
65
65
var obj = {
66
- bar : 1,
67
- foo : 2,
68
- baz : 3
66
+ a : 1,
67
+ b : 2,
68
+ c : 3
69
69
};
70
- obj.bar = undefined;
71
- obj.foo = null;
72
- delete obj.baz ;
70
+ obj.a = undefined;
71
+ obj.b = null;
72
+ delete obj.c ;
73
73
74
74
for(var i in obj) {
75
75
if (obj.hasOwnProperty(i)) {
76
76
console.log(i, '' + obj[i]);
77
77
}
78
78
}
79
79
80
- The above outputs both ` bar undefined` and ` foo null` - only ` baz ` was
80
+ The above outputs both ` a undefined` and ` b null` - only ` c ` was
81
81
removed and is therefore missing from the output.
82
82
83
83
### Notation of Keys
0 commit comments