Skip to content

Commit 2c039ef

Browse files
committed
Removing hard-coded numbers from section headings
1 parent 3f423d6 commit 2c039ef

File tree

9 files changed

+172
-172
lines changed

9 files changed

+172
-172
lines changed

ch01.asciidoc

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ JavaScript has gone from being a 1995 marketing ploy to gain a tactical advantag
66

77
How did JavaScript get here, and where is it going next?
88

9-
=== 1.1 A Brief History of JavaScript Standards
9+
=== A Brief History of JavaScript Standards
1010

1111
Back in 1995, Netscape envisioned a dynamic web beyond what HTML could offer. Brendan Eich was initially brought into Netscape to develop a language that was functionally akin to Scheme, but for the browser. Once he joined, he learned that upper management wanted it to look like Java and a deal to that effect was already underway.
1212

@@ -43,7 +43,7 @@ In parallel with the ES6 effort, in 2012 the WHATWG (a standards body interested
4343
The sixth edition is a significant milestone in the history of JavaScript. Besides the dozens of new features, ES6 marks a key inflection point where ECMAScript would become a rolling standard.
4444

4545
[[ecmascript_as_a_rolling_standard]]
46-
=== 1.2 ECMAScript as a Rolling Standard
46+
=== ECMAScript as a Rolling Standard
4747

4848
Having spent ten years without observing significant change to the language specification after ES3, and four years for ES6 to materialize, it was clear the TC39 process needed to improve. The revision process used to be deadline-driven. Any delay in arriving at consensus would cause long wait periods between revisions, which lead to feature creep, causing more delays. Minor revisions were delayed by large additions to the specification, and large additions faced pressure to finalize so that the revision would be pushed through avoiding further delays.
4949

@@ -67,7 +67,7 @@ New releases of the specification are expected to be published every year from n
6767

6868
The streamlined proposal process combined with the yearly cut into standardization translates into a more consistent publication process, and it also means specification revision numbers are becoming less important. The focus is now on proposal stagesfootnoteref:[tc39-proposals], and we can expect references to specific revisions of the ECMAScript standard to become more uncommon.
6969

70-
=== 1.3 Browser Support and Complementary Tooling
70+
=== Browser Support and Complementary Tooling
7171

7272
A stage 3 candidate recommendation proposal is most likely to make it into the specification in the next cut, provided two independent implementations land in JavaScript engines. Effectively, stage 3 proposals are considered safe to use in real-world applications, be it through an experimental engine implementation, a polyfill, or using a compiler. Stage 2 and earlier proposals are also used in the wild by JavaScript developers, tightening the feedback loop between implementors and consumers.
7373

@@ -81,7 +81,7 @@ The same applies to ES7 and beyond. As new versions of the language specificatio
8181

8282
Let's talk about how you can use Babel in as part of your workflow.
8383

84-
==== 1.3.1 Introduction to the Babel transpiler
84+
==== Introduction to the Babel transpiler
8585

8686
Babel can compile modern JavaScript code using ES6 features into ES5. It produces human-readable code, making it more welcoming when we don't have a firm grasp on all of the new features we're using.
8787

@@ -216,7 +216,7 @@ console.log(double(3))
216216

217217
Let's jump into a different kind of tool, the `eslint` code linter, which can help us establish a code quality baseline for our applications.
218218

219-
==== 1.3.2 Code Quality and Consistency with ESLint
219+
==== Code Quality and Consistency with ESLint
220220

221221
As we develop a codebase we factor out snippets that are redundant or no longer useful, write new pieces of code, delete features that are no longer relevant or necessary, and shift chunks of code around while accomodating a new architecture. As the codebase grows, the team working on it changes as well: at first it may be a handful of people or even one person, but as the project grows in size so might the team.
222222

@@ -318,7 +318,7 @@ A similar kind of tool can be found in `prettier`, which can be used to automati
318318

319319
Now that you know how to compile modern JavaScript into something every browser understands, and how to properly lint and format your code, let's jump into ES6 feature themes and the future of JavaScript.
320320

321-
=== 1.4 Feature Themes in ES6
321+
=== Feature Themes in ES6
322322

323323
ES6 is big: the language specification went from 258 pages in ES5.1 to over double that amount in ES6, at 566 pages. Each change to the specification falls in some of a few different categories:
324324

@@ -342,7 +342,7 @@ We are getting a new module system that's native to JavaScript. After going over
342342

343343
Due to the sheer amount of changes introduced by ES6, it's hard to reconcile its new features with our pre-existing knowledge of JavaScript. We'll spend all of <<practical-considerations>> analyzing the merits and importance of different individual features in ES6, so that you have a practical grounding upon which you can start experimenting with ES6 right away.
344344

345-
=== 1.5 Future of JavaScript
345+
=== Future of JavaScript
346346

347347
The JavaScript language has evolved from its humble beginnings in 1995, to the formidable language it is today. While ES6 is a great step forward, it's not the finish line. Given we can expect new specification updates every year, it's important to learn how to stay up to date with the specification.
348348

ch02.asciidoc

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ The sixth edition of the language comes with a plethora of non-breaking syntax i
55

66
Object literals get a few syntax changes in ES6, and they're a good place to start.
77

8-
=== 2.1 Object Literals
8+
=== Object Literals
99

1010
An object literal is any object declaration using the `{}` shorthand syntax, such as the following example.
1111

@@ -20,7 +20,7 @@ var book = {
2020

2121
ES6 brings a few improvements to object literal syntax: property value shorthands, computed property names, and method definitions. Let's go through them and describe their use cases as well.
2222

23-
==== 2.1.1 Property Value Shorthands
23+
==== Property Value Shorthands
2424

2525
Sometimes we declare objects with one or more properties whose values are references to variables by the same name. For example we might have a `listeners` collection, and in order to assign it to a property called `listeners` of an object literal, we have to repeat its name. The following snippet has a typical example where we have an object literal declaration with a couple of these repetitive properties.
2626

@@ -62,7 +62,7 @@ function clear() {
6262

6363
That's the first of many ES6 features that are aimed towards reducing complexity in the code you have to maintain. Once you get used to the syntax, you'll notice that code readability and developer productivity get boosts as well.
6464

65-
==== 2.1.2 Computed Property Names
65+
==== Computed Property Names
6666

6767
Sometimes you have to declare objects that contain properties with names based on variables or other JavaScript expressions, as shown in the following piece of code written in ES5. For this example, assume that `expertise` is provided to you as a function parameter, and is not a value you know beforehand.
6868

@@ -153,7 +153,7 @@ function getEnvelope(type, description) {
153153

154154
The last enhancement coming to object literals is about functions.
155155

156-
==== 2.1.3 Method Definitions
156+
==== Method Definitions
157157

158158
Typically, you can declare methods on an object by adding properties to it. In the next snippet we're creating an small event emitter which supports multiple kinds of events. It comes with an `emitter#on` method that can be used to register event listeners, and an `emitter#emit` method that can be used to raise events.
159159

@@ -204,7 +204,7 @@ var emitter = {
204204
Arrow functions are another way of declaring functions in ES6, and they come in several flavors. Let's investigate what arrow functions are, how they can be declared, and how they behave semantically.
205205

206206
[[arrow_functions]]
207-
=== 2.2 Arrow Functions
207+
=== Arrow Functions
208208

209209
In JavaScript you typically declare functions using code like the following, where you have a name, a list of parameters, and a function body.
210210

@@ -237,7 +237,7 @@ While arrow functions look very similar to your typical anonymous function, they
237237

238238
Let's dig into their semantic differences with traditional functions, the many ways to declare an arrow function, and practical use cases.
239239

240-
==== 2.2.1 Lexical Scoping
240+
==== Lexical Scoping
241241

242242
In the body of an arrow function, `this`, `arguments` and `super` point to the containing scope, since arrow functions don't create a new scope. Consider the following example. We have a `timer` object with a `seconds` counter and a `start` method defined using the syntax we've learned about earlier. We then start the timer, wait for a few seconds, and log the current amount of elapsed `seconds`.
243243

@@ -290,7 +290,7 @@ In this case, the `arguments` object refers to the context of the `puzzle` funct
290290

291291
I've mentioned there's several flavors of arrow functions, but so far we've only looked at their fully fleshed version. What are the others way to represent an arrow function?
292292

293-
==== 2.2.2 Arrow Function Flavors
293+
==== Arrow Function Flavors
294294

295295
Let's look one more time at the arrow function syntax we've learned so far.
296296

@@ -364,7 +364,7 @@ Wrapping the expression in parenthesis fixes these issues, because the compiler
364364

365365
Now that you understand arrow functions, let's ponder about their merits and where they might be a good fit.
366366

367-
==== 2.2.3 Merits and Use Cases
367+
==== Merits and Use Cases
368368

369369
As a rule of thumb, you shouldn't blindly adopt ES6 features wherever you can. Instead, it's best to reason about each case individually and see whether adopting the new feature actually improves code readibility and maintainability. ES6 features are not strictly better than what we had all along, and it's a bad idea to treat them as such.
370370

@@ -395,11 +395,11 @@ Arrow functions are neat when it comes to defining anonymous functions that shou
395395
// <- 8
396396
----
397397

398-
=== 2.3 Assignment Destructuring
398+
=== Assignment Destructuring
399399

400400
This is one of the most flexible and expressive features in ES6. It's also one of the simplest. It binds properties to as many variables as you need. It works with objects, arrays, and even in `function` parameter lists. Let's go step by step, starting with objects.
401401

402-
==== 2.3.1 Destructuring Objects
402+
==== Destructuring Objects
403403

404404
Imagine you had a program with some comic book characters, Bruce Wayne being one of them, and you want to refer to properties in the object that describes him. Here's the example object we'll be using for Batman.
405405

@@ -544,7 +544,7 @@ This flavor of destructuring is probably the least useful, as `characterBoots =
544544

545545
That's it, as far as objects go, in terms of destructuring. What about arrays?
546546

547-
==== 2.3.2 Destructuring Arrays
547+
==== Destructuring Arrays
548548

549549
The syntax for destructuring arrays is similar to that of objects. The following example shows a `coordinates` object that's destructured into two variables: `x` and `y`. Note how the notation uses square brackets instead of curly braces, this denotes we're using array destructuring instead of object destructuring. Instead of having to sprinkle your code with implementation details like `x = coordinates[0]`, with destructuring you can convey your meaning clearly and without explicitly referencing the indices, naming the values instead.
550550

@@ -598,7 +598,7 @@ var right = 7
598598

599599
The last area of destructuring we'll be covering is function parameters.
600600

601-
==== 2.3.3 Function Parameter Defaults
601+
==== Function Parameter Defaults
602602

603603
Function parameters in ES6 enjoy the ability of specifying default values as well. The following example defines a default `exponent` with the most commonly used value.
604604

@@ -651,7 +651,7 @@ carFactory({ make: 2000 })
651651

652652
We can mix function parameter default values with destructuring, and get the best of both worlds.
653653

654-
==== 2.3.4 Function Parameter Destructuring
654+
==== Function Parameter Destructuring
655655

656656
A better approach than merely providing a default value might be to destructure `options` entirely, providing default values for each property, individually, within the destructuring pattern. This approach also lets you reference each option without going through an `options` object, but you lose the ability to reference `options` directly, which might represent an issue in some situations.
657657

@@ -716,7 +716,7 @@ getCarProductModel(car)
716716

717717
Besides default values and filling an `options` object, let's explore what else destructuring is good at.
718718

719-
==== 2.3.5 Use Cases for Destructuring
719+
==== Use Cases for Destructuring
720720

721721
Whenever there's a function that returns an object or an array, destructuring makes it much terser to interact with. The following example shows a function that returns an object with some coordinates, where we grab only the ones we're interested in: `x` and `y`. We're avoiding an intermediate `point` variable declaration that often gets in the way without adding a lot of value to the readability of your code.
722722

@@ -765,7 +765,7 @@ var [, year, month, day] = matches
765765

766766
Let's turn our attention to spread and rest operators next.
767767

768-
=== 2.4 Rest Parameters and Spread Operator
768+
=== Rest Parameters and Spread Operator
769769

770770
Before ES6, interacting with an arbitrary amount of function parameters was complicated. You had to use `arguments`, which isn't an array but has a `length` property. Usually you'd end up casting the `arguments` object into an actual array using `Array#slice.call`, and going from there, as shown in the following snippet.
771771

@@ -781,7 +781,7 @@ join('first', 'second', 'third')
781781

782782
ES6 has a better solution to the problem, and that's rest parameters.
783783

784-
==== 2.4.1 Rest Parameters
784+
==== Rest Parameters
785785

786786
You can now precede the last parameter in any JavaScript function with three dots, converting it into an special "rest parameter". When the rest parameter is the only parameter in a function, it gets all arguments passed to the function: it works just like the `.slice` solution we saw earlier, but you avoid the need for a complicated construct like `arguments`, and it's specified in the parameter list.
787787

@@ -830,7 +830,7 @@ console.log(sumAll(1, 2, 5))
830830

831831
Next up we have the spread operator. It's also denoted with three dots, but it serves a slightly different purpose.
832832

833-
==== 2.4.2 Spread Operator
833+
==== Spread Operator
834834

835835
The spread operator can be used to cast any iterable object into an array. Spreading effectively expands an expression onto a target such as an array literal or a function call. The following example uses `...arguments` to cast function parameters into an array literal.
836836

@@ -956,7 +956,7 @@ The following table summarizes the use cases we've discussed for the spread oper
956956
|=======
957957

958958
[[template_literals]]
959-
=== 2.5 Template Literals
959+
=== Template Literals
960960

961961
Template literals are a vast improvement upon regular JavaScript strings. Instead of using single or double quotes, template literals are declared using backticks, as shown next.
962962

@@ -974,7 +974,7 @@ var text = `I'm "amazed" at these opportunities!`
974974

975975
One of the most appealing features of template literals is their ability to interpolate JavaScript expressions.
976976

977-
==== 2.5.1 String Interpolation
977+
==== String Interpolation
978978

979979
With template literals, you're able to interpolate any JavaScript expressions inside your templates. When the template literal expression is reached, it's evaluated and you get back the compiled result. The following example interpolates a `name` variable into a template literal.
980980

@@ -1014,7 +1014,7 @@ You could even nest template literals, as they are also valid JavaScript express
10141014

10151015
Another perk of template literals is their multiline string representation support.
10161016

1017-
==== 2.5.2 Multiline Template Literals
1017+
==== Multiline Template Literals
10181018

10191019
Before template literals, if you wanted to represent strings in multiple lines of JavaScript, you had to resort to escaping, concatenation, arrays, or even ellaborate hacks using comments. The following snippet summarizes some of the most common ways multiline string representations prior to ES6.
10201020

@@ -1124,7 +1124,7 @@ function unindent(text) {
11241124

11251125
Sometimes, it might be a good idea to pre-process the results of interpolated expressions before inserting them into your templates. For these advanced kinds of use cases, it's possible to use another feature of template literals called tagged templates.
11261126

1127-
==== 2.5.3 Tagged Templates
1127+
==== Tagged Templates
11281128

11291129
By default, JavaScript interprets `\` as an escape character with special meaning. For example, `\n` is interpreted as a newline, `\u00f1` is interpreted as `ñ`, etcetera. You could avoid these rules using the `String.raw` tagged template. The next snippet shows a template literal using `String.raw` which prevents `\n` from being interpreted as a newline.
11301130

@@ -1210,7 +1210,7 @@ console.log(html)
12101210

12111211
Phew, that malicious `<iframe>` almost got us. Rounding out ES6 syntax changes, we have the `let` and `const` statements.
12121212

1213-
=== 2.6 Let and Const Statements
1213+
=== Let and Const Statements
12141214

12151215
The `let` statement is one of the most well-known features in ES6. It works like a `var` statement, but it has different scoping rules.
12161216

@@ -1245,7 +1245,7 @@ function isItTwo(value) {
12451245

12461246
Whether we like it or not, hoisting is more confusing than having block-scoped variables would be. Block scoping works on the curly braces level, rather than the function level.
12471247

1248-
==== 2.6.1 Block Scoping and Let Statements
1248+
==== Block Scoping and Let Statements
12491249

12501250
Instead of having to declare a new `function` if we want a deeper scoping level, block scoping allows you to just leverage existing code branches like those in `if`, `for`, or `while` statements; you could also create new `{}` blocks arbitrarily. As you may or may not know, the JavaScript language allows us to create an indiscriminate number of blocks, just because we want to.
12511251

@@ -1324,7 +1324,7 @@ printNumbers()
13241324

13251325
One more thing of note about `let` is a concept called the "Temporal Dead Zone".
13261326

1327-
==== 2.6.2 Temporal Dead Zone
1327+
==== Temporal Dead Zone
13281328

13291329
In so many words: if you have code such as the following code snippet, it'll throw. Once execution enters a scope, and until a `let` statement is reached, attempting to access the variable for said `let` statement will throw. This is known as the Temporal Dead Zone (TDZ).
13301330

@@ -1391,7 +1391,7 @@ The whole point of the TDZ is to make it easier to catch errors where accessing
13911391

13921392
We made it through the temporal dead zone! It's now time to cover `const`, a similar statement to `let` but with a few major differences.
13931393

1394-
==== 2.6.3 Const Statements
1394+
==== Const Statements
13951395

13961396
The `const` statement is block scoped like `let`, and it follows TDZ semantics as well. In fact, TDZ semantics were implemented because of `const`, and then TDZ was also applied to `let` for consistency. The reason why `const` needed TDZ semantics is that it would otherwise have been possible to assign a value to a hoisted `const` variable before reaching the `const` declaration, meaning that the declaration itself would throw. The temporal dead zone defines a solution that solves the problem of making `const` assignment possible only at declaration time, helps avoid potential issues when using `let`, and also makes it easy to eventually implement other features that benefit from TDZ semantics.
13971397

@@ -1467,7 +1467,7 @@ frozen.push('Water')
14671467

14681468
Let's take a moment to discuss the merits of `const` and `let`.
14691469

1470-
==== 2.6.4 Merits of Const and Let
1470+
==== Merits of Const and Let
14711471

14721472
New features should never be used for the sake of using new features. ES6 features should be used where they genuinely improve code readability and maintainability. The `let` statement is able to, in many cases, simplify pieces of code where you'd otherwise declare `var` statements at the top of a function just so that hoisting doesn't produce unexpected results. Using the `let` statement you'd be able to place your declarations at the top of a code block, instead of the top of the whole function, reducing the latency in mental trips to the top of the scope.
14731473

0 commit comments

Comments
 (0)