Skip to content

Commit 1e50ea1

Browse files
committed
Some more updated
1 parent 5ec31ac commit 1e50ea1

File tree

3 files changed

+34
-3
lines changed

3 files changed

+34
-3
lines changed

doc/objects.md

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ object [inherits](#prototype) from `Object.prototype` and has no
3737
// a new object with a property called 'test' with value 12
3838
var bar = {test: 12};
3939

40-
### Access of properties
40+
### Accessing properties
4141

4242
The properties of an object can be accessed in two ways. Either via the dot
4343
notation, or the square bracket notation.
@@ -56,6 +56,30 @@ Both notation are identical in their workings, the only difference being that
5656
the square bracket notation allows for dynamic setting of properties as well as
5757
the use of property names that would otherwise lead to a syntax error.
5858

59+
### Deleting properties
60+
61+
The only way to actually remove a property from an object is to use the `delete`
62+
keyword, setting the property to `undefined` or `null` does **only** remove the
63+
value associated with the property, but not the key.
64+
65+
var obj = {
66+
bar: 1,
67+
foo: 2,
68+
baz: 3
69+
};
70+
obj.bar = undefined;
71+
obj.foo = null;
72+
delete obj.baz;
73+
74+
for(var i in obj) {
75+
if (obj.hasOwnProperty(i)) {
76+
console.log(i, '' + obj[i]);
77+
}
78+
}
79+
80+
The aboves outputs both `bar undefined` and `foo null`, only `baz` got actually
81+
removed and is therefore missing from the output.
82+
5983
### Notation of keys
6084

6185
var test = {

doc/scopes.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
## Scopes and namespaces
22

3-
Although JavaScript deals fine with the block scope syntax of two matching curly
3+
Although JavaScript deals fine with the block syntax of two matching curly
44
braces, it does **not** support block scope; thus, all that is left is the
55
*function scope*.
66

7+
function test() { // a scope
8+
for(var i = 0; i < 10; i++) { // not a scope
9+
// count
10+
}
11+
console.log(i); // 10
12+
}
13+
714
> **Note:** When not used in an assignment or as a function argument, the `{...}`
815
> notation will get interpreted as a block statement and **not** as an `Object`.
916
> This, in conjunction with [automatic insertion of semicolons](#semicolon),

doc/typeof.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ to the object whose `[[Class]]` value should be retrieved.
6262

6363
typeof foo !== 'undefined'
6464

65-
The above will check whether `foo` was actually declared or not, since just
65+
The above will check whether `foo` was actually declared or not; just
6666
referencing it would result in a `ReferenceError`. This is the only thing
6767
`typeof` is actually useful for.
6868

0 commit comments

Comments
 (0)