Skip to content

Commit

Permalink
Use consistent formatting for all macros (#29006)
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh-Cena authored Sep 12, 2023
1 parent c2445ce commit 4f86aad
Show file tree
Hide file tree
Showing 79 changed files with 384 additions and 389 deletions.
2 changes: 1 addition & 1 deletion files/en-us/web/javascript/closures/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ setX(6);
console.log(getX()); // 6
```

Closures can close over imported values as well, which are regarded as _live {{glossary("binding", "bindings")}}_, because when the original value changes, the imported one changes accordingly.
Closures can close over imported values as well, which are regarded as _live {{Glossary("binding", "bindings")}}_, because when the original value changes, the imported one changes accordingly.

```js
// myModule.js
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ slug: Web/JavaScript/Enumerability_and_ownership_of_properties
page-type: guide
---

{{JsSidebar("More")}}
{{jsSidebar("More")}}

Every property in JavaScript objects can be classified by three factors:

Expand Down
2 changes: 1 addition & 1 deletion files/en-us/web/javascript/event_loop/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ slug: Web/JavaScript/Event_loop
page-type: guide
---

{{JsSidebar("Advanced")}}
{{jsSidebar("Advanced")}}

JavaScript has a runtime model based on an **event loop**, which is responsible for executing the code, collecting and processing events, and executing queued sub-tasks. This model is quite different from models in other languages like C and Java.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ page-type: guide
---

{{jsSidebar("JavaScript Guide")}}
{{PreviousNext("Web/JavaScript/Guide/Grammar_and_types",
"Web/JavaScript/Guide/Loops_and_iteration")}}
{{PreviousNext("Web/JavaScript/Guide/Grammar_and_types", "Web/JavaScript/Guide/Loops_and_iteration")}}

JavaScript supports a compact set of statements, specifically
control flow statements, that you can use to incorporate a great deal of interactivity
Expand Down Expand Up @@ -534,5 +533,4 @@ try {
}
```

{{PreviousNext("Web/JavaScript/Guide/Grammar_and_types",
"Web/JavaScript/Guide/Loops_and_iteration")}}
{{PreviousNext("Web/JavaScript/Guide/Grammar_and_types", "Web/JavaScript/Guide/Loops_and_iteration")}}
4 changes: 2 additions & 2 deletions files/en-us/web/javascript/guide/functions/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -721,9 +721,9 @@ JavaScript has several top-level, built-in functions:
- : The **`encodeURI()`** method encodes a Uniform Resource Identifier (URI) by replacing each instance of certain characters by one, two, three, or four escape sequences representing the UTF-8 encoding of the character (will only be four escape sequences for characters composed of two "surrogate" characters).
- {{jsxref("Global_Objects/encodeURIComponent", "encodeURIComponent()")}}
- : The **`encodeURIComponent()`** method encodes a Uniform Resource Identifier (URI) component by replacing each instance of certain characters by one, two, three, or four escape sequences representing the UTF-8 encoding of the character (will only be four escape sequences for characters composed of two "surrogate" characters).
- {{jsxref("Global_Objects/escape", "escape()")}} {{Deprecated_Inline}}
- {{jsxref("Global_Objects/escape", "escape()")}} {{deprecated_inline}}
- : The **`escape()`** method computes a new string in which certain characters have been replaced by a hexadecimal escape sequence. It's deprecated and you should use {{jsxref("Global_Objects/encodeURI", "encodeURI()")}} or {{jsxref("Global_Objects/encodeURIComponent", "encodeURIComponent()")}} instead.
- {{jsxref("Global_Objects/unescape", "unescape()")}} {{Deprecated_Inline}}
- {{jsxref("Global_Objects/unescape", "unescape()")}} {{deprecated_inline}}
- : The **`unescape()`** method computes a new string in which hexadecimal escape sequences are replaced with the character that it represents. The escape sequences might be introduced by a function like {{jsxref("Global_Objects/escape", "escape()")}}. It's deprecated and you should use {{jsxref("Global_Objects/decodeURI", "decodeURI()")}} or {{jsxref("Global_Objects/decodeURIComponent", "decodeURIComponent()")}} instead.

{{PreviousNext("Web/JavaScript/Guide/Loops_and_iteration", "Web/JavaScript/Guide/Expressions_and_operators")}}
6 changes: 3 additions & 3 deletions files/en-us/web/javascript/guide/grammar_and_types/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ A semicolon is not necessary after a statement if it is written on its own line.
It is considered best practice, however, to always write a semicolon after a statement, even when it is not strictly needed. This practice reduces the chances of bugs getting into the code.

The source text of JavaScript script gets scanned from left to right, and is converted into a sequence of input elements which are _tokens_, _control characters_, _line terminators_, _comments_, or {{glossary("whitespace")}}. (Spaces, tabs, and newline characters are considered whitespace.)
The source text of JavaScript script gets scanned from left to right, and is converted into a sequence of input elements which are _tokens_, _control characters_, _line terminators_, _comments_, or {{Glossary("whitespace")}}. (Spaces, tabs, and newline characters are considered whitespace.)

## Comments

Expand Down Expand Up @@ -115,7 +115,7 @@ A variable may belong to one of the following [scopes](/en-US/docs/Glossary/Scop

- Global scope: The default scope for all code running in script mode.
- Module scope: The scope for code running in module mode.
- Function scope: The scope created with a {{glossary("function")}}.
- Function scope: The scope created with a {{Glossary("function")}}.

In addition, variables declared with [`let`](/en-US/docs/Web/JavaScript/Reference/Statements/let) or [`const`](/en-US/docs/Web/JavaScript/Reference/Statements/const) can belong to an additional scope:

Expand Down Expand Up @@ -482,7 +482,7 @@ console.log(car.manyCars.b); // Jeep
console.log(car[7]); // Mazda
```

Object property names can be any string, including the empty string. If the property name would not be a valid JavaScript {{Glossary("Identifier","identifier")}} or number, it must be enclosed in quotes.
Object property names can be any string, including the empty string. If the property name would not be a valid JavaScript {{Glossary("Identifier", "identifier")}} or number, it must be enclosed in quotes.

Property names that are not valid identifiers cannot be accessed as a dot (`.`) property.

Expand Down
10 changes: 5 additions & 5 deletions files/en-us/web/javascript/guide/indexed_collections/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const arr3 = [];
arr3.length = arrayLength;
```

> **Note:** In the above code, `arrayLength` must be a `Number`. Otherwise, an array with a single element (the provided value) will be created. Calling `arr.length` will return `arrayLength`, but the array doesn't contain any elements. A {{jsxref("Statements/for...in","for...in")}} loop will not find any property on the array.
> **Note:** In the above code, `arrayLength` must be a `Number`. Otherwise, an array with a single element (the provided value) will be created. Calling `arr.length` will return `arrayLength`, but the array doesn't contain any elements. A {{jsxref("Statements/for...in", "for...in")}} loop will not find any property on the array.
In addition to a newly defined variable as shown above, arrays can also be assigned as a property of a new or an existing object:

Expand Down Expand Up @@ -233,7 +233,7 @@ nonsparseArray.forEach((element) => {
// fourth
```

Since JavaScript array elements are saved as standard object properties, it is not advisable to iterate through JavaScript arrays using {{jsxref("Statements/for...in","for...in")}} loops, because normal elements and all enumerable properties will be listed.
Since JavaScript array elements are saved as standard object properties, it is not advisable to iterate through JavaScript arrays using {{jsxref("Statements/for...in", "for...in")}} loops, because normal elements and all enumerable properties will be listed.

### Array methods

Expand Down Expand Up @@ -527,7 +527,7 @@ console.log(result.vegetables);
// [{ name: "asparagus", type: "vegetables" }]
```

Note that the returned object references the _same_ elements as the original array (not {{glossary("deep copy","deep copies")}}). Changing the internal structure of these elements will be reflected in both the original array and the returned object.
Note that the returned object references the _same_ elements as the original array (not {{Glossary("deep copy", "deep copies")}}). Changing the internal structure of these elements will be reflected in both the original array and the returned object.

If you can't use a string as the key, for example, if the information to group is associated with an object that might change, then you can instead use {{jsxref("Map.groupBy()")}}. This is very similar to `Object.groupBy()` except that it groups the elements of the array into a {{jsxref("Map")}} that can use an arbitrary value ({{Glossary("object")}} or {{Glossary("primitive")}}) as a key.

Expand Down Expand Up @@ -632,7 +632,7 @@ For example, when an array is the result of a match between a regular expression

## Working with array-like objects

Some JavaScript objects, such as the [`NodeList`](/en-US/docs/Web/API/NodeList) returned by [`document.getElementsByTagName()`](/en-US/docs/Web/API/Document/getElementsByTagName) or the {{jsxref("Functions/arguments","arguments")}} object made available within the body of a function, look and behave like arrays on the surface but do not share all of their methods. The `arguments` object provides a {{jsxref("Global_Objects/Function/length","length")}} attribute but does not implement array methods like [`forEach()`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach).
Some JavaScript objects, such as the [`NodeList`](/en-US/docs/Web/API/NodeList) returned by [`document.getElementsByTagName()`](/en-US/docs/Web/API/Document/getElementsByTagName) or the {{jsxref("Functions/arguments", "arguments")}} object made available within the body of a function, look and behave like arrays on the surface but do not share all of their methods. The `arguments` object provides a {{jsxref("Function/length", "length")}} attribute but does not implement array methods like [`forEach()`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach).

Array methods cannot be called directly on array-like objects.

Expand All @@ -644,7 +644,7 @@ function printArguments() {
}
```

But you can call them indirectly using {{jsxref("Global_Objects/Function/call","Function.prototype.call()")}}.
But you can call them indirectly using {{jsxref("Function.prototype.call()")}}.

```js example-good
function printArguments() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ page-type: guide

{{jsSidebar("JavaScript Guide")}} {{PreviousNext("Web/JavaScript/Guide/Typed_arrays", "Web/JavaScript/Guide/Meta_programming")}}

Iterators and Generators bring the concept of iteration directly into the core language and provide a mechanism for customizing the behavior of {{jsxref("Statements/for...of","for...of")}} loops.
Iterators and Generators bring the concept of iteration directly into the core language and provide a mechanism for customizing the behavior of {{jsxref("Statements/for...of", "for...of")}} loops.

For details, see also:

- [Iteration protocols](/en-US/docs/Web/JavaScript/Reference/Iteration_protocols)
- {{jsxref("Statements/for...of","for...of")}}
- {{jsxref("Statements/function*","function*")}} and {{jsxref("Generator")}}
- {{jsxref("Operators/yield","yield")}} and {{jsxref("Operators/yield*","yield*")}}
- {{jsxref("Statements/for...of", "for...of")}}
- {{jsxref("Statements/function*", "function*")}} and {{jsxref("Generator")}}
- {{jsxref("Operators/yield", "yield")}} and {{jsxref("Operators/yield*", "yield*")}}

## Iterators

Expand Down Expand Up @@ -73,7 +73,7 @@ console.log("Iterated over sequence of size:", result.value); // [5 numbers retu
## Generator functions

While custom iterators are a useful tool, their creation requires careful programming due to the need to explicitly maintain their internal state. **Generator functions** provide a powerful alternative: they allow you to define an iterative algorithm by writing a single function whose execution is not continuous. Generator functions are written using the {{jsxref("Statements/function*","function*")}} syntax.
While custom iterators are a useful tool, their creation requires careful programming due to the need to explicitly maintain their internal state. **Generator functions** provide a powerful alternative: they allow you to define an iterative algorithm by writing a single function whose execution is not continuous. Generator functions are written using the {{jsxref("Statements/function*", "function*")}} syntax.

When called, generator functions do not initially execute their code. Instead, they return a special type of iterator, called a **Generator**. When a value is consumed by calling the generator's `next` method, the Generator function executes until it encounters the `yield` keyword.

Expand Down Expand Up @@ -163,7 +163,7 @@ for (const value of myIterable) {

### Syntaxes expecting iterables

Some statements and expressions expect iterables. For example: the {{jsxref("Statements/for...of","for-of")}} loops, {{jsxref("Operators/yield*","yield*")}}.
Some statements and expressions expect iterables. For example: the {{jsxref("Statements/for...of", "for...of")}} loops, {{jsxref("Operators/yield*", "yield*")}}.

```js
for (const value of ["a", "b", "c"]) {
Expand Down Expand Up @@ -192,7 +192,7 @@ a;

Generators compute their `yield`ed values _on demand_, which allows them to efficiently represent sequences that are expensive to compute (or even infinite sequences, as demonstrated above).

The {{jsxref("Global_Objects/Generator/next","next()")}} method also accepts a value, which can be used to modify the internal state of the generator. A value passed to `next()` will be received by `yield` .
The {{jsxref("Generator/next", "next()")}} method also accepts a value, which can be used to modify the internal state of the generator. A value passed to `next()` will be received by `yield` .

> **Note:** A value passed to the _first_ invocation of `next()` is always ignored.
Expand Down Expand Up @@ -226,10 +226,10 @@ console.log(sequence.next().value); // 1
console.log(sequence.next().value); // 2
```

You can force a generator to throw an exception by calling its {{jsxref("Global_Objects/Generator/throw","throw()")}} method and passing the exception value it should throw. This exception will be thrown from the current suspended context of the generator, as if the `yield` that is currently suspended were instead a `throw value` statement.
You can force a generator to throw an exception by calling its {{jsxref("Generator/throw", "throw()")}} method and passing the exception value it should throw. This exception will be thrown from the current suspended context of the generator, as if the `yield` that is currently suspended were instead a `throw value` statement.

If the exception is not caught from within the generator, it will propagate up through the call to `throw()`, and subsequent calls to `next()` will result in the `done` property being `true`.

Generators have a {{jsxref("Global_Objects/Generator/return","return(value)")}} method that returns the given value and finishes the generator itself.
Generators have a {{jsxref("Generator/return", "return()")}} method that returns the given value and finishes the generator itself.

{{PreviousNext("Web/JavaScript/Guide/Typed_arrays", "Web/JavaScript/Guide/Meta_programming")}}
4 changes: 2 additions & 2 deletions files/en-us/web/javascript/guide/keyed_collections/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ This chapter introduces collections of data which are indexed by a key; `Map` an

A {{jsxref("Map")}} object is a simple key/value map and can iterate its elements in insertion order.

The following code shows some basic operations with a `Map`. See also the {{jsxref("Map")}} reference page for more examples and the complete API. You can use a {{jsxref("Statements/for...of","for...of")}} loop to return an array of `[key, value]` for each iteration.
The following code shows some basic operations with a `Map`. See also the {{jsxref("Map")}} reference page for more examples and the complete API. You can use a {{jsxref("Statements/for...of", "for...of")}} loop to return an array of `[key, value]` for each iteration.

```js
const sayings = new Map();
Expand Down Expand Up @@ -42,7 +42,7 @@ sayings.size; // 0

Traditionally, {{jsxref("Object", "objects", "", 1)}} have been used to map strings to values. Objects allow you to set keys to values, retrieve those values, delete keys, and detect whether something is stored at a key. `Map` objects, however, have a few more advantages that make them better maps.

- The keys of an `Object` are {{jsxref("Global_Objects/String","Strings")}} or {{jsxref("Global_Objects/Symbol","Symbols")}}, where they can be of any value for a `Map`.
- The keys of an `Object` are [strings](/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) or [symbols](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol), where they can be of any value for a `Map`.
- You can get the `size` of a `Map` easily, while you have to manually keep track of size for an `Object`.
- The iteration of maps is in insertion order of the elements.
- An `Object` has a prototype, so there are default keys in the map. (This can be bypassed using `map = Object.create(null)`.)
Expand Down
Loading

0 comments on commit 4f86aad

Please sign in to comment.