Skip to content

Commit 1ba420f

Browse files
committed
fixes
1 parent 05f4502 commit 1ba420f

File tree

2 files changed

+14
-19
lines changed

2 files changed

+14
-19
lines changed

1-js/05-data-types/01-primitives-methods/1-string-new-property/solution.md

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,21 @@ let str = "Hello";
66

77
str.test = 5; // (*)
88

9-
alert(str.test);
9+
alert(str.test);
1010
```
1111

12-
There may be two kinds of result:
13-
1. `undefined`
14-
2. An error.
12+
Depending on whether you have `use strict` or not, the result may be:
13+
1. `undefined` (no string)
14+
2. An error (strict mode).
1515

1616
Why? Let's replay what's happening at line `(*)`:
1717

1818
1. When a property of `str` is accessed, a "wrapper object" is created.
19-
2. The operation with the property is carried out on it. So, the object gets the `test` property.
20-
3. The operation finishes and the "wrapper object" disappears.
19+
2. In strict mode, writing into it is an error.
20+
3. Otherwise, the operation with the property is carried on, the object gets the `test` property, but after that the "wrapper object" disappears.
2121

22-
So, on the last line, `str` has no trace of the property. A new wrapper object for every object operation on a string.
23-
24-
Some browsers though may decide to further limit the programmer and disallow to assign properties to primitives at all. That's why in practice we can also see errors at line `(*)`. It's a little bit farther from the specification though.
22+
So, without strict mode, in the last line `str` has no trace of the property.
2523

2624
**This example clearly shows that primitives are not objects.**
2725

28-
They just can not store data.
29-
30-
All property/method operations are performed with the help of temporary objects.
31-
26+
They can't store additional data.

1-js/05-data-types/01-primitives-methods/article.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ A primitive
1414
An object
1515

1616
- Is capable of storing multiple values as properties.
17-
- Can be created with `{}`, for instance: `{name: "John", age: 30}`. There are other kinds of objects in JavaScript; functions, for example, are objects.
17+
- Can be created with `{}`, for instance: `{name: "John", age: 30}`. There are other kinds of objects in JavaScript: functions, for example, are objects.
1818

1919
One of the best things about objects is that we can store a function as one of its properties.
2020

@@ -48,7 +48,7 @@ The solution looks a little bit awkward, but here it is:
4848

4949
1. Primitives are still primitive. A single value, as desired.
5050
2. The language allows access to methods and properties of strings, numbers, booleans and symbols.
51-
3. When this happens, a special "object wrapper" that provides the extra functionality is created, and then is destroyed.
51+
3. In order for that to work, a special "object wrapper" that provides the extra functionality is created, and then is destroyed.
5252

5353
The "object wrappers" are different for each primitive type and are called: `String`, `Number`, `Boolean` and `Symbol`. Thus, they provide different sets of methods.
5454

@@ -91,18 +91,18 @@ In JavaScript, that's also possible for historical reasons, but highly **unrecom
9191
For instance:
9292

9393
```js run
94-
alert( typeof 1 ); // "number"
94+
alert( typeof 0 ); // "number"
9595

96-
alert( typeof new Number(1) ); // "object"!
96+
alert( typeof new Number(0) ); // "object"!
9797
```
9898

99-
And because what follows, `zero`, is an object, the alert will show up:
99+
Objects are always truthy in `if`, so here the alert will show up:
100100

101101
```js run
102102
let zero = new Number(0);
103103

104104
if (zero) { // zero is true, because it's an object
105-
alert( "zero is truthy?!?" );
105+
alert( "zero is truthy!?!" );
106106
}
107107
```
108108

0 commit comments

Comments
 (0)