You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: get-started/apA.md
+1-1
Original file line number
Diff line number
Diff line change
@@ -37,7 +37,7 @@ console.log(yourName);
37
37
38
38
See how `yourName` wasn't affected by the re-assignment of `myName` to `"Frank"`? That's because each variable holds its own copy of the value.
39
39
40
-
By contrast, references are the idea that two or more variables are pointing at the same value, such that modifying this shared value would be reflected by an access via any of those references. In JS, only object values (arrays, objects, functions, etc.) are treated as references.
40
+
By contrast, references are the idea that two or more variables are pointing at the same value, such that modifying this shared value would be reflected by access via any of those references. In JS, only object values (arrays, objects, functions, etc.) are treated as references.
Copy file name to clipboardExpand all lines: get-started/apB.md
+1-1
Original file line number
Diff line number
Diff line change
@@ -138,7 +138,7 @@ Once you have code that works, *compare* your solution(s) to the code in "Sugges
138
138
139
139
## Suggested Solutions
140
140
141
-
Keep in mind that these suggested solutions are just that: suggestions. There's many different ways to solve these practice exercises. Compare your approach to what you see here, and consider the pros and cons of each.
141
+
Keep in mind that these suggested solutions are just that: suggestions. There are many different ways to solve these practice exercises. Compare your approach to what you see here, and consider the pros and cons of each.
142
142
143
143
Suggested solution for "Comparisons" (Pillar 3) practice:
Copy file name to clipboardExpand all lines: get-started/ch4.md
+1-1
Original file line number
Diff line number
Diff line change
@@ -89,7 +89,7 @@ On the other hand, there's a *grain* you really should pay attention to and foll
89
89
90
90
Can you make your JS program look like a Java, C#, or Perl program? What about Python or Ruby, or even PHP? To varying degrees, sure you can. But should you?
91
91
92
-
No, I don't think you should. I think you should learn and embrace the JS way, and make your JS programs as JS'y as is practical. Some will think that means sloppy and informal programming, but I don't mean that at all. I just mean that JS has a lot of patterns and idioms that are recognizably "JS," and going with that *grain* is the general path to best success.
92
+
No, I don't think you should. I think you should learn and embrace the JS way, and make your JS programs as JS'y as is practical. Some will think that means sloppy and informal programming, but I don't mean that at all. I just mean that JS has a lot of patterns and idioms that are recognizably "JS," and going with that *grain* is the general path to the best success.
93
93
94
94
Finally, maybe the most important *grain* to recognize is how the existing program(s) you're working on, and developers you're working with, do stuff. Don't read these books and then try to change *all that grain* in your existing projects over night. That approach will always fail.
Copy file name to clipboardExpand all lines: objects-classes/ch1.md
+3-3
Original file line number
Diff line number
Diff line change
@@ -11,7 +11,7 @@ This is one of the most pervasive, but most incorrect, "facts" that perpetually
11
11
12
12
JS definitely has objects, but that doesn't mean that all values are objects. Nevertheless, objects are arguably the most important (and varied!) value type in the language, so mastering them is critical to your JS journey.
13
13
14
-
The object mechanism is certainly the most flexible and powerful container type -- something you put other values into; every JS program you write will use them in one way or another. But that's not why objects deserve top billing for this book. Objects are the the foundation for the second of JS's three pillars: the prototype.
14
+
The object mechanism is certainly the most flexible and powerful container type -- something you put other values into; every JS program you write will use them in one way or another. But that's not why objects deserve top billing for this book. Objects are the foundation for the second of JS's three pillars: the prototype.
15
15
16
16
Why are prototypes (along with the `this` keyword, covered later in the book) so core to JS as to be one of its three pillars? Among other things, prototypes are how JS's object system can express the class design pattern, one of the most widely relied on design patterns in all of programming.
17
17
@@ -145,7 +145,7 @@ The `42` property name will be treated as an integer property name (aka, index);
145
145
| :--- |
146
146
| If you need to actually use an object as a key/property name, never rely on this computed string coercion; its behavior is surprising and almost certainly not what's expected, so program bugs are likely to occur. Instead, use a more specialized data structure, called a `Map` (added in ES6), where objects used as property "names" are left as-is instead of being coerced to a string value. |
147
147
148
-
As with with `[myObj]` above, you can *compute* any **property name** (distinct from computing the property value) at the time of object literal definition:
148
+
As with `[myObj]` above, you can *compute* any **property name** (distinct from computing the property value) at the time of object literal definition:
Added in ES6, `Object.entries(..)`retieves this list of entries -- containing only owned an enumerable properties; see the "Property Descriptors" section in the next chapter -- from a source object.
370
+
Added in ES6, `Object.entries(..)`retrieves this list of entries -- containing only owned an enumerable properties; see the "Property Descriptors" section in the next chapter -- from a source object.
371
371
372
372
Such a list can be looped/iterated over, potentially assigning properties to another existing object. However, it's also possible to create a new object from a list of entries, using `Object.fromEntries(..)` (added in ES2019):
|`eval("this")` would be sensitive to strict-mode, but `(1,eval)("this")` is not, and therefor reliably gives us the `globalThis` in any program. |
1202
1202
1203
-
Unfortunately, the `new Function(..)` and `(1,eval)(..)` approaches both have an important limitation: that code will be blocked in browser-based JS code if the the app is served with certain Content-Security-Policy (CSP) restrictions, disallowing dynamic code evaluation (for security reasons).
1203
+
Unfortunately, the `new Function(..)` and `(1,eval)(..)` approaches both have an important limitation: that code will be blocked in browser-based JS code if the app is served with certain Content-Security-Policy (CSP) restrictions, disallowing dynamic code evaluation (for security reasons).
1204
1204
1205
1205
Can we get around this? Yes, mostly. [^globalThisPolyfill]
Copy file name to clipboardExpand all lines: scope-closures/apA.md
+2-2
Original file line number
Diff line number
Diff line change
@@ -933,7 +933,7 @@ The latter one is definitely not an example of closure, at least not in any usef
933
933
934
934
### Defer to Closure
935
935
936
-
By the way, Chapter 7 briefly mentioned partial application and currying (which *do* rely on closure!). This is a interesting scenario where manual currying can be used:
936
+
By the way, Chapter 7 briefly mentioned partial application and currying (which *do* rely on closure!). This is an interesting scenario where manual currying can be used:
937
937
938
938
```js
939
939
functionprintLabels(labels) {
@@ -1013,7 +1013,7 @@ But I strongly prefer, and always use myself, the former `publicAPI` form. Two r
1013
1013
1014
1014
Whatever the case may be, it just seems rather silly to me that we *wouldn't* maintain a reference to access our own API. Right?
1015
1015
1016
-
### Asynchronous Module Defintion (AMD)
1016
+
### Asynchronous Module Definition (AMD)
1017
1017
1018
1018
Another variation on the classic module form is AMD-style modules (popular several years back), such as those supported by the RequireJS utility:
Copy file name to clipboardExpand all lines: scope-closures/ch5.md
+1-1
Original file line number
Diff line number
Diff line change
@@ -530,7 +530,7 @@ The term coined by TC39 to refer to this *period of time* from the entering of a
530
530
531
531
The TDZ is the time window where a variable exists but is still uninitialized, and therefore cannot be accessed in any way. Only the execution of the instructions left by *Compiler* at the point of the original declaration can do that initialization. After that moment, the TDZ is done, and the variable is free to be used for the rest of the scope.
532
532
533
-
A `var` also has technically has a TDZ, but it's zero in length and thus unobservable to our programs! Only `let` and `const` have an observable TDZ.
533
+
A `var` also technically has a TDZ, but it's zero in length and thus unobservable to our programs! Only `let` and `const` have an observable TDZ.
534
534
535
535
By the way, "temporal" in TDZ does indeed refer to *time* not *position in code*. Consider:
Copy file name to clipboardExpand all lines: types-grammar/ch1.md
+3-3
Original file line number
Diff line number
Diff line change
@@ -312,7 +312,7 @@ If `"` or `'` are used to delimit a string literal, the contents are only parsed
312
312
313
313
For single-character escape sequences, the following characters are recognized after a `\`: `b`, `f`, `n`, `r`, `t`, `v`, `0`, `'`, `"`, and `\`. For example, `\n` means new-line, `\t` means tab, etc.
314
314
315
-
If a `\` is followed by any other character (except `x` and `u` -- explained below), like for example `\k`, that sequence is interpted as the `\` being an unnecessary escape, which is thus dropped, leaving just the literal character itself (`k`).
315
+
If a `\` is followed by any other character (except `x` and `u` -- explained below), like for example `\k`, that sequence is interpreted as the `\` being an unnecessary escape, which is thus dropped, leaving just the literal character itself (`k`).
316
316
317
317
To include a `"` in the middle of a `"`-delimited string literal, use the `\"` escape sequence. Similarly, if you're including a `'` character in the middle of a `'`-delimited string literal, use the `\'` escape sequence. By contrast, a `'` does *not* need to be escaped inside a `"`-delimited string, nor vice versa.
318
318
@@ -365,7 +365,7 @@ Because the end-of-line `\` turns the new-line character into a line continuatio
365
365
366
366
Multi-character escape sequences may be hexadecimal or Unicode sequences.
367
367
368
-
Hexidecimal escape sequences are used to encode any of the base ASCII characters (codes 0-255), and look like `\x` followed by exactly two hexadecimal characters (`0-9` and `a-f` / `A-F` -- case insensitive). For example, `A9` or `a9` are decimal value `169`, which corresponds to:
368
+
Hexadecimal escape sequences are used to encode any of the base ASCII characters (codes 0-255), and look like `\x` followed by exactly two hexadecimal characters (`0-9` and `a-f` / `A-F` -- case insensitive). For example, `A9` or `a9` are decimal value `169`, which corresponds to:
369
369
370
370
```js
371
371
copyright = "\xA9"; // or "\xa9"
@@ -490,7 +490,7 @@ familyEmoji; // 👩👩👦👦
490
490
491
491
This emoji is *not* a single registered Unicode code-point, and as such, there's no *normalization* that can be performed to compose these 7 separate code-points into a single entity. The visual rendering logic for such composite symbols is quite complex, well beyond what most of JS developers want to embed into our programs. Libraries do exist for handling some of this logic, but they're often large and still don't necessarily cover all of the nuances/variations.
492
492
493
-
Unlike surrogate pairs and combining marks, the symbols in grapheme clusters can in fact act as standalone characters, but have the special combining behavior when placed adjactent to each other.
493
+
Unlike surrogate pairs and combining marks, the symbols in grapheme clusters can in fact act as standalone characters, but have the special combining behavior when placed adjacent to each other.
494
494
495
495
This kind of complexity significantly affects length computations, comparison, sorting, and many other common string-oriented operations.
Copy file name to clipboardExpand all lines: types-grammar/ch3.md
+1-1
Original file line number
Diff line number
Diff line change
@@ -7,7 +7,7 @@
7
7
8
8
Now that we're comfortable with the built-in primitive types, we turn our attention to the `object` types in JS.
9
9
10
-
I could write a whole book talking about objects in-depth; in fact, I already did! The "Objects & Classes" title of this series covers objects in-depth already, so make sure you've read that before continuning with this chapter.
10
+
I could write a whole book talking about objects in-depth; in fact, I already did! The "Objects & Classes" title of this series covers objects in-depth already, so make sure you've read that before continuing with this chapter.
11
11
12
12
Rather than repeat that book's content, here we'll focus our attention on how the `object` value-type behaves and interacts with other values in JS.
Copy file name to clipboardExpand all lines: types-grammar/ch4.md
+2-2
Original file line number
Diff line number
Diff line change
@@ -800,7 +800,7 @@ We need to expect and plan for that rather than allowing it to surprise us with
800
800
801
801
### To Primitive
802
802
803
-
Most operators in JS, including those we've see with coercions to `string` and `number`, are designed to run against primitive values. When any of these operators is used instead against an object value, the abstract `ToPrimitive` algorithm (as described earlier) is activated to coerce the object to a primitive.
803
+
Most operators in JS, including those we've seen with coercions to `string` and `number`, are designed to run against primitive values. When any of these operators is used instead against an object value, the abstract `ToPrimitive` algorithm (as described earlier) is activated to coerce the object to a primitive.
804
804
805
805
Let's set up an object we can use to inspect how different operations behave:
806
806
@@ -1490,7 +1490,7 @@ By contrast, JS is **dynamically-typed** (meaning types are discovered and manag
1490
1490
1491
1491
Does a dynamically-typed system automatically mean you're programming with less type-awareness? Many would argue that, but I disagree.
1492
1492
1493
-
Ido not at all think that declaring statictypes (annotations, as in TypeScript) is the only way to accomplish effective type-awareness. Clearly, though, proponents ofstatic-typing believe that's is the *best* way.
1493
+
Ido not at all think that declaring statictypes (annotations, as in TypeScript) is the only way to accomplish effective type-awareness. Clearly, though, proponents ofstatic-typing believe that is the *best* way.
1494
1494
1495
1495
Let me illustrate type-awareness without TypeScript's static typing. Consider this variable declaration:
0 commit comments