diff --git a/files/en-us/web/javascript/closures/index.md b/files/en-us/web/javascript/closures/index.md index 1bd49222409fdd7..63d091ae51c060d 100644 --- a/files/en-us/web/javascript/closures/index.md +++ b/files/en-us/web/javascript/closures/index.md @@ -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 diff --git a/files/en-us/web/javascript/enumerability_and_ownership_of_properties/index.md b/files/en-us/web/javascript/enumerability_and_ownership_of_properties/index.md index f5dcd1189f44c0e..b99302abcaeb5a5 100644 --- a/files/en-us/web/javascript/enumerability_and_ownership_of_properties/index.md +++ b/files/en-us/web/javascript/enumerability_and_ownership_of_properties/index.md @@ -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: diff --git a/files/en-us/web/javascript/event_loop/index.md b/files/en-us/web/javascript/event_loop/index.md index 43d2af9e6529090..9c078fd417c2e78 100644 --- a/files/en-us/web/javascript/event_loop/index.md +++ b/files/en-us/web/javascript/event_loop/index.md @@ -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. diff --git a/files/en-us/web/javascript/guide/control_flow_and_error_handling/index.md b/files/en-us/web/javascript/guide/control_flow_and_error_handling/index.md index 04de9be594fa6c3..ef44a17b7d7c26c 100644 --- a/files/en-us/web/javascript/guide/control_flow_and_error_handling/index.md +++ b/files/en-us/web/javascript/guide/control_flow_and_error_handling/index.md @@ -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 @@ -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")}} diff --git a/files/en-us/web/javascript/guide/functions/index.md b/files/en-us/web/javascript/guide/functions/index.md index 77299ff3e4bdce7..93e33ecd1f2d528 100644 --- a/files/en-us/web/javascript/guide/functions/index.md +++ b/files/en-us/web/javascript/guide/functions/index.md @@ -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")}} diff --git a/files/en-us/web/javascript/guide/grammar_and_types/index.md b/files/en-us/web/javascript/guide/grammar_and_types/index.md index 5f9915ee63ffb9d..930f66ee378de28 100644 --- a/files/en-us/web/javascript/guide/grammar_and_types/index.md +++ b/files/en-us/web/javascript/guide/grammar_and_types/index.md @@ -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 @@ -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: @@ -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. diff --git a/files/en-us/web/javascript/guide/indexed_collections/index.md b/files/en-us/web/javascript/guide/indexed_collections/index.md index e6f1f229c065330..340b0a710b8bd79 100644 --- a/files/en-us/web/javascript/guide/indexed_collections/index.md +++ b/files/en-us/web/javascript/guide/indexed_collections/index.md @@ -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: @@ -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 @@ -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. @@ -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. @@ -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() { diff --git a/files/en-us/web/javascript/guide/iterators_and_generators/index.md b/files/en-us/web/javascript/guide/iterators_and_generators/index.md index e3c4840f955a6e3..1327e9bf8060884 100644 --- a/files/en-us/web/javascript/guide/iterators_and_generators/index.md +++ b/files/en-us/web/javascript/guide/iterators_and_generators/index.md @@ -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 @@ -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. @@ -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"]) { @@ -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. @@ -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")}} diff --git a/files/en-us/web/javascript/guide/keyed_collections/index.md b/files/en-us/web/javascript/guide/keyed_collections/index.md index eb5782dbed848c8..1ffd3dfcf14afc0 100644 --- a/files/en-us/web/javascript/guide/keyed_collections/index.md +++ b/files/en-us/web/javascript/guide/keyed_collections/index.md @@ -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(); @@ -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)`.) diff --git a/files/en-us/web/javascript/guide/loops_and_iteration/index.md b/files/en-us/web/javascript/guide/loops_and_iteration/index.md index c78f949265364df..63df504b52d31cc 100644 --- a/files/en-us/web/javascript/guide/loops_and_iteration/index.md +++ b/files/en-us/web/javascript/guide/loops_and_iteration/index.md @@ -5,8 +5,7 @@ page-type: guide --- {{jsSidebar("JavaScript Guide")}} -{{PreviousNext("Web/JavaScript/Guide/Control_flow_and_error_handling", - "Web/JavaScript/Guide/Functions")}} +{{PreviousNext("Web/JavaScript/Guide/Control_flow_and_error_handling", "Web/JavaScript/Guide/Functions")}} Loops offer a quick and easy way to do something repeatedly. This chapter of the [JavaScript Guide](/en-US/docs/Web/JavaScript/Guide) @@ -44,7 +43,7 @@ The statements for loops provided in JavaScript are: ## for statement -A {{jsxref("statements/for","for")}} loop repeats until a specified condition evaluates to false. The JavaScript `for` loop is similar to the Java and C `for` loop. +A {{jsxref("Statements/for", "for")}} loop repeats until a specified condition evaluates to false. The JavaScript `for` loop is similar to the Java and C `for` loop. A `for` statement looks as follows: @@ -146,7 +145,7 @@ do { ## while statement -A {{jsxref("statements/while","while")}} statement executes its statements as long as a +A {{jsxref("Statements/while", "while")}} statement executes its statements as long as a specified condition evaluates to `true`. A `while` statement looks as follows: @@ -212,7 +211,7 @@ while (true) { ## labeled statement -A {{jsxref("statements/label","label")}} provides a statement with an identifier that +A {{jsxref("Statements/label", "label")}} provides a statement with an identifier that lets you refer to it elsewhere in your program. For example, you can use a label to identify a loop, and then use the `break` or `continue` statements to indicate whether a program should interrupt the loop or continue its execution. @@ -230,7 +229,7 @@ any statement. For examples of using labeled statements, see the examples of `br ## break statement -Use the {{jsxref("statements/break","break")}} statement to terminate a loop, +Use the {{jsxref("Statements/break", "break")}} statement to terminate a loop, `switch`, or in conjunction with a labeled statement. - When you use `break` without a label, it terminates the innermost @@ -285,7 +284,7 @@ labelCancelLoops: while (true) { ## continue statement -The {{jsxref("statements/continue","continue")}} statement can be used to restart a +The {{jsxref("Statements/continue", "continue")}} statement can be used to restart a `while`, `do-while`, `for`, or `label` statement. @@ -366,7 +365,7 @@ checkiandj: while (i < 4) { ## for...in statement -The {{jsxref("statements/for...in","for...in")}} statement iterates a specified +The {{jsxref("Statements/for...in", "for...in")}} statement iterates a specified variable over all the enumerable properties of an object. For each distinct property, JavaScript executes the specified statements. A `for...in` statement looks as follows: @@ -406,17 +405,17 @@ Although it may be tempting to use this as a way to iterate over {{jsxref("Array elements, the `for...in` statement will return the name of your user-defined properties in addition to the numeric indexes. -Therefore, it is better to use a traditional {{jsxref("statements/for","for")}} loop +Therefore, it is better to use a traditional {{jsxref("Statements/for", "for")}} loop with a numeric index when iterating over arrays, because the `for...in` statement iterates over user-defined properties in addition to the array elements, if you modify the Array object (such as adding custom properties or methods). ## for...of statement -The {{jsxref("statements/for...of","for...of")}} statement creates a loop Iterating +The {{jsxref("Statements/for...of", "for...of")}} statement creates a loop Iterating over [iterable objects](/en-US/docs/Web/JavaScript/Reference/Iteration_protocols) (including {{jsxref("Array")}}, {{jsxref("Map")}}, {{jsxref("Set")}}, -{{jsxref("functions/arguments","arguments")}} object and so on), invoking a custom +{{jsxref("Functions/arguments", "arguments")}} object and so on), invoking a custom iteration hook with statements to be executed for the value of each distinct property. ```js-nolint @@ -425,7 +424,7 @@ for (variable of object) ``` The following example shows the difference between a `for...of` loop and a -{{jsxref("statements/for...in","for...in")}} loop. While `for...in` iterates +{{jsxref("Statements/for...in", "for...in")}} loop. While `for...in` iterates over property names, `for...of` iterates over property values: ```js @@ -455,5 +454,4 @@ for (const [key, val] of Object.entries(obj)) { // "bar" 2 ``` -{{PreviousNext("Web/JavaScript/Guide/Control_flow_and_error_handling", - "Web/JavaScript/Guide/Functions")}} +{{PreviousNext("Web/JavaScript/Guide/Control_flow_and_error_handling", "Web/JavaScript/Guide/Functions")}} diff --git a/files/en-us/web/javascript/guide/meta_programming/index.md b/files/en-us/web/javascript/guide/meta_programming/index.md index b9d52ffda6fac35..7628b1612bca62c 100644 --- a/files/en-us/web/javascript/guide/meta_programming/index.md +++ b/files/en-us/web/javascript/guide/meta_programming/index.md @@ -34,7 +34,7 @@ Additional examples are available on the {{jsxref("Proxy")}} reference page. The following terms are used when talking about the functionality of proxies. -- {{jsxref("Global_Objects/Proxy/Proxy","handler","","true")}} +- {{jsxref("Proxy/Proxy", "handler", "", "true")}} - : Placeholder object which contains traps. - traps - : The methods that provide property access. (This is analogous to the concept of _traps_ in operating systems.) @@ -412,7 +412,7 @@ console.log(typeof proxy); // "object", typeof doesn't trigger any trap ## Reflection -{{jsxref("Reflect")}} is a built-in object that provides methods for interceptable JavaScript operations. The methods are the same as those of the {{jsxref("Global_Objects/Proxy/Proxy","proxy handlers","","true")}}. +{{jsxref("Reflect")}} is a built-in object that provides methods for interceptable JavaScript operations. The methods are the same as those of the [proxy handler's](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy/Proxy). `Reflect` is not a function object. @@ -450,7 +450,7 @@ Reflect.apply("".charAt, "ponies", [3]); ### Checking if property definition has been successful -With {{jsxref("Object.defineProperty")}}, which returns an object if successful, or throws a {{jsxref("TypeError")}} otherwise, you would use a {{jsxref("Statements/try...catch","try...catch")}} block to catch any error that occurred while defining a property. Because {{jsxref("Reflect.defineProperty")}} returns a Boolean success status, you can just use an {{jsxref("Statements/if...else","if...else")}} block here: +With {{jsxref("Object.defineProperty")}}, which returns an object if successful, or throws a {{jsxref("TypeError")}} otherwise, you would use a {{jsxref("Statements/try...catch", "try...catch")}} block to catch any error that occurred while defining a property. Because {{jsxref("Reflect.defineProperty()")}} returns a Boolean success status, you can just use an {{jsxref("Statements/if...else", "if...else")}} block here: ```js if (Reflect.defineProperty(target, property, attributes)) { diff --git a/files/en-us/web/javascript/guide/modules/index.md b/files/en-us/web/javascript/guide/modules/index.md index 9bd206efe428577..efae97705680dfd 100644 --- a/files/en-us/web/javascript/guide/modules/index.md +++ b/files/en-us/web/javascript/guide/modules/index.md @@ -7,7 +7,7 @@ browser-compat: - javascript.statements.export --- -{{JSSidebar("JavaScript Guide")}}{{Previous("Web/JavaScript/Guide/Meta_programming")}} +{{jsSidebar("JavaScript Guide")}}{{Previous("Web/JavaScript/Guide/Meta_programming")}} This guide gives you all you need to get started with JavaScript module syntax. @@ -19,7 +19,7 @@ It has therefore made sense in recent years to start thinking about providing me The good news is that modern browsers have started to support module functionality natively, and this is what this article is all about. This can only be a good thing ā€” browsers can optimize loading of modules, making it more efficient than having to use a library and do all of that extra client-side processing and extra round trips. -Use of native JavaScript modules is dependent on the {{JSxRef("Statements/import", "import")}} and {{JSxRef("Statements/export", "export")}} statements; these are supported in browsers as shown in the compatibility table below. +Use of native JavaScript modules is dependent on the {{jsxref("Statements/import", "import")}} and {{jsxref("Statements/export", "export")}} statements; these are supported in browsers as shown in the compatibility table below. ## Browser compatibility @@ -83,7 +83,7 @@ It is also worth noting that: ## Exporting module features -The first thing you do to get access to module features is export them. This is done using the {{JSxRef("Statements/export", "export")}} statement. +The first thing you do to get access to module features is export them. This is done using the {{jsxref("Statements/export", "export")}} statement. The easiest way to use it is to place it in front of any items you want exported out of the module, for example: @@ -114,7 +114,7 @@ Once you've exported some features out of your module, you need to import them i import { name, draw, reportArea, reportPerimeter } from "./modules/square.js"; ``` -You use the {{JSxRef("Statements/import", "import")}} statement, followed by a comma-separated list of the features you want to import wrapped in curly braces, followed by the keyword `from`, followed by the _module specifier_. +You use the {{jsxref("Statements/import", "import")}} statement, followed by a comma-separated list of the features you want to import wrapped in curly braces, followed by the keyword `from`, followed by the _module specifier_. The _module specifier_ provides a string that the JavaScript environment can resolve to a path to the module file. In a browser, this could be a path relative to the site root, which for our `basic-modules` example would be `/js-examples/module-examples/basic-modules`. @@ -385,7 +385,7 @@ You can only use `import` and `export` statements inside modules, not regular sc ## Other differences between modules and standard scripts - You need to pay attention to local testing ā€” if you try to load the HTML file locally (i.e. with a `file://` URL), you'll run into CORS errors due to JavaScript module security requirements. You need to do your testing through a server. -- Also, note that you might get different behavior from sections of script defined inside modules as opposed to in standard scripts. This is because modules use {{JSxRef("Strict_mode", "strict mode", "", 1)}} automatically. +- Also, note that you might get different behavior from sections of script defined inside modules as opposed to in standard scripts. This is because modules use {{jsxref("Strict_mode", "strict mode", "", 1)}} automatically. - There is no need to use the `defer` attribute (see [`