@@ -6,9 +6,9 @@ Everything in JavaScript acts like an object, with the only two exceptions being
66 false.toString(); // 'false'
77 [1, 2, 3].toString(); // '1,2,3'
88
9- function Foo (){}
10- Foo .bar = 1;
11- Foo .bar; // 1
9+ function sayHello (){}
10+ sayHello .bar = 1;
11+ sayHello .bar; // 1
1212
1313A common misconception is that number literals cannot be used as
1414objects. 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
3232plain object. This new object [ inherits] ( #object.prototype ) from ` Object.prototype ` and
3333does not have [ own properties] ( #object.hasownproperty ) defined.
3434
35- var foo = {}; // a new empty object
35+ var names = {}; // a new empty object
3636
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' };
3939
4040### Accessing Properties
4141
4242The properties of an object can be accessed in two ways, via either the dot
4343notation or the square bracket notation.
4444
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
4848
4949 var get = 'name';
50- foo [ get] ; // kitten
50+ pet [ get] ; // kitten
5151
52- foo .1234; // SyntaxError
53- foo [ '1234'] ; // works
52+ pet .1234; // SyntaxError
53+ pet [ '1234'] ; // works
5454
5555The notations work almost identically, with the only difference being that the
5656square bracket notation allows for dynamic setting of properties and
@@ -63,21 +63,21 @@ operator; setting the property to `undefined` or `null` only removes the
6363* value* associated with the property, but not the * key* .
6464
6565 var obj = {
66- bar : 1,
67- foo : 2,
68- baz : 3
66+ a : 1,
67+ b : 2,
68+ c : 3
6969 };
70- obj.bar = undefined;
71- obj.foo = null;
72- delete obj.baz ;
70+ obj.a = undefined;
71+ obj.b = null;
72+ delete obj.c ;
7373
7474 for(var i in obj) {
7575 if (obj.hasOwnProperty(i)) {
7676 console.log(i, '' + obj[i]);
7777 }
7878 }
7979
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
8181removed and is therefore missing from the output.
8282
8383### Notation of Keys
0 commit comments