From 6740fa6e28055bb85fe038e9327b8b4b377a876d Mon Sep 17 00:00:00 2001 From: Will <> Date: Mon, 26 Apr 2021 16:31:33 -0700 Subject: [PATCH 1/5] In JS docs, use Note: consistently at the start of notes --- .../a_re-introduction_to_javascript/index.html | 14 +++++++------- files/en-us/web/javascript/closures/index.html | 2 +- .../web/javascript/data_structures/index.html | 4 ++-- .../control_flow_and_error_handling/index.html | 6 +++--- .../guide/details_of_the_object_model/index.html | 2 +- .../web/javascript/guide/functions/index.html | 2 +- .../javascript/guide/grammar_and_types/index.html | 14 +++++++------- .../javascript/guide/keyed_collections/index.html | 3 +-- .../regular_expressions/assertions/index.html | 4 ++-- .../character_classes/index.html | 2 +- .../regular_expressions/cheatsheet/index.html | 10 +++++----- .../groups_and_ranges/index.html | 4 ++-- .../inheritance_and_the_prototype_chain/index.html | 2 +- .../classes/public_class_fields/index.html | 4 ++-- .../reference/errors/too_much_recursion/index.html | 2 +- .../functions/arguments/length/index.html | 2 +- .../reference/functions/arrow_functions/index.html | 2 +- .../javascript/reference/functions/get/index.html | 2 +- .../global_objects/array/every/index.html | 2 +- .../global_objects/array/findindex/index.html | 2 +- .../global_objects/array/foreach/index.html | 11 ++++------- .../reference/global_objects/array/from/index.html | 4 ++-- .../global_objects/array/reduce/index.html | 2 +- .../reference/global_objects/array/some/index.html | 2 +- .../reference/global_objects/array/sort/index.html | 4 ++-- .../global_objects/array/values/index.html | 2 +- .../reference/global_objects/date/index.html | 2 +- .../reference/global_objects/date/parse/index.html | 6 +++--- .../reference/global_objects/error/index.html | 2 +- .../global_objects/function/call/index.html | 6 +++--- .../global_objects/function/name/index.html | 2 +- .../intl/collator/collator/index.html | 8 ++++---- .../intl/datetimeformat/datetimeformat/index.html | 11 +++-------- .../reference/global_objects/map/index.html | 2 +- .../global_objects/math/random/index.html | 4 ++-- .../global_objects/object/constructor/index.html | 2 +- .../global_objects/object/isprototypeof/index.html | 2 +- .../global_objects/object/valueof/index.html | 2 +- .../reference/global_objects/promise/index.html | 2 +- .../global_objects/promise/then/index.html | 2 +- .../global_objects/proxy/proxy/set/index.html | 5 +---- .../reflect/defineproperty/index.html | 2 +- .../reference/global_objects/regexp/index.html | 2 +- .../sharedarraybuffer/planned_changes/index.html | 2 +- .../sharedarraybuffer/sharedarraybuffer/index.html | 2 +- .../reference/global_objects/string/big/index.html | 2 +- .../global_objects/string/fontcolor/index.html | 2 +- .../global_objects/string/fontsize/index.html | 2 +- .../reference/global_objects/string/index.html | 4 ++-- .../global_objects/string/replaceall/index.html | 2 +- .../global_objects/typedarray/values/index.html | 4 ++-- .../reference/global_objects/undefined/index.html | 2 +- .../operators/destructuring_assignment/index.html | 4 ++-- .../javascript/reference/operators/new/index.html | 6 +++--- .../javascript/reference/operators/this/index.html | 9 +++++---- .../reference/statements/async_function/index.html | 9 +++------ .../reference/statements/for-await...of/index.html | 4 ++-- .../javascript/reference/statements/let/index.html | 4 ++-- .../reference/statements/return/index.html | 6 ++++-- .../reference/statements/with/index.html | 6 ++++-- .../javascript/reference/strict_mode/index.html | 3 +-- 61 files changed, 117 insertions(+), 128 deletions(-) diff --git a/files/en-us/web/javascript/a_re-introduction_to_javascript/index.html b/files/en-us/web/javascript/a_re-introduction_to_javascript/index.html index a546d97cba5e635..c74932899884801 100644 --- a/files/en-us/web/javascript/a_re-introduction_to_javascript/index.html +++ b/files/en-us/web/javascript/a_re-introduction_to_javascript/index.html @@ -18,7 +18,7 @@
Several months later, Microsoft released JScript with Internet Explorer 3. It was a mostly-compatible JavaScript work-alike. Several months after that, Netscape submitted JavaScript to Ecma International, a European standards organization, which resulted in the first edition of the ECMAScript standard that year. The standard received a significant update as ECMAScript edition 3 in 1999, and it has stayed pretty much stable ever since. The fourth edition was abandoned, due to political differences concerning language complexity. Many parts of the fourth edition formed the basis for ECMAScript edition 5, published in December of 2009, and for the 6th major edition of the standard, published in June of 2015.
Because it is more familiar, we will refer to ECMAScript as "JavaScript" from this point on.
+Note: Because it is more familiar, we will refer to ECMAScript as "JavaScript" from this point on.
Unlike most programming languages, the JavaScript language has no concept of input or output. It is designed to run as a scripting language in a host environment, and it is up to the host environment to provide mechanisms for communicating with the outside world. The most common host environment is the browser, but JavaScript interpreters can also be found in a huge list of other places, including Adobe Acrobat, Adobe Photoshop, SVG images, Yahoo's Widget engine, server-side environments such as Node.js, NoSQL databases like the open source Apache CouchDB, embedded computers, complete desktop environments like GNOME (one of the most popular GUIs for GNU/Linux operating systems), and others.
@@ -155,7 +155,7 @@NaN
if there is an invalid character contained within it. Just try parsing the string "10.2abc" with each method by yourself in the console and you'll understand the differences better.NaN
if there is an invalid character contained within it. Just try parsing the string "10.2abc" with each method by yourself in the console and you'll understand the differences better.Starting in ECMAScript 5, reserved words may be used as object property names "in the buff". This means that they don't need to be "clothed" in quotes when defining object literals. See the ES5 Spec.
+Note: Starting in ECMAScript 5, reserved words may be used as object property names "in the buff". This means that they don't need to be "clothed" in quotes when defining object literals. See the ES5 Spec.
For more on objects and prototypes see Object.prototype. For an explanation of object prototypes and the object prototype chains see Inheritance and the prototype chain.
Starting in ECMAScript 2015, object keys can be defined by the variable using bracket notation upon being created. {[phoneType]: 12345}
is possible instead of just var userPhone = {}; userPhone[phoneType] = 12345
.
Note: Starting in ECMAScript 2015, object keys can be defined by the variable using bracket notation upon being created. {[phoneType]: 12345}
is possible instead of just var userPhone = {}; userPhone[phoneType] = 12345
.
avg()
function takes a comma-separated list of arguments — but what if you want to find the average of an array? You could just rewrite the function as follows:The second argument to apply()
is the array to use as arguments; the first will be discussed later on. This emphasizes the fact that functions are objects too.
You can achieve the same result using the spread operator in the function call.
+Note: You can achieve the same result using the spread operator in the function call.
For instance: avg(...numbers)
In classic Object Oriented Programming, objects are collections of data and methods that operate on that data. JavaScript is a prototype-based language that contains no class statement, as you'd find in C++ or Java (this is sometimes confusing for programmers accustomed to languages with a class statement). Instead, JavaScript uses functions as classes. Let's consider a person object with first and last name fields. There are two ways in which the name might be displayed: as "first last" or as "last, first". Using the functions and objects that we've discussed previously, we could display the data like this:
diff --git a/files/en-us/web/javascript/closures/index.html b/files/en-us/web/javascript/closures/index.html index 9da4b52045d683f..46bfe1636bba41e 100644 --- a/files/en-us/web/javascript/closures/index.html +++ b/files/en-us/web/javascript/closures/index.html @@ -208,7 +208,7 @@Notice how the two counters maintain their independence from one another. Each closure references a different version of the privateCounter
variable through its own closure. Each time one of the counters is called, its lexical environment changes by changing the value of this variable. Changes to the variable value in one closure don't affect the value in the other closure.
Using closures in this way provides benefits that are normally associated with object-oriented programming. In particular, data hiding and encapsulation.
+Note: Using closures in this way provides benefits that are normally associated with object-oriented programming. In particular, data hiding and encapsulation.
To check for the largest available value or smallest available value within {{jsxref("Infinity", "±Infinity")}}, you can use the constants {{jsxref("Number.MAX_VALUE")}} or {{jsxref("Number.MIN_VALUE")}}.
Starting with ECMAScript 2015, you are also able to check if a number is in the double-precision floating-point number range using {{jsxref("Number.isSafeInteger()")}} as well as {{jsxref("Number.MAX_SAFE_INTEGER")}} and {{jsxref("Number.MIN_SAFE_INTEGER")}}.
+Note: Starting with ECMAScript 2015, you are also able to check if a number is in the double-precision floating-point number range using {{jsxref("Number.isSafeInteger()")}} as well as {{jsxref("Number.MAX_SAFE_INTEGER")}} and {{jsxref("Number.MIN_SAFE_INTEGER")}}.
Beyond this range, integers in JavaScript are not safe anymore and will be a double-precision floating point approximation of the value.
Although a number often represents only its value, JavaScript provides {{jsxref("Operators", "binary (bitwise) operators")}}.
Caution: Although bitwise operators can be used to represent several Boolean values within a single number using bit masking, this is usually considered a bad practice. JavaScript offers other means to represent a set of Booleans (like an array of Booleans, or an object with Boolean values assigned to named properties). Bit masking also tends to make the code more difficult to read, understand, and maintain.
+Note: Although bitwise operators can be used to represent several Boolean values within a single number using bit masking, this is usually considered a bad practice. JavaScript offers other means to represent a set of Booleans (like an array of Booleans, or an object with Boolean values assigned to named properties). Bit masking also tends to make the code more difficult to read, understand, and maintain.
It may be necessary to use such techniques in very constrained environments, like when trying to cope with the limitations of local storage, or in extreme cases (such as when each bit over the network counts). This technique should only be considered when it is the last measure that can be taken to optimize size.
diff --git a/files/en-us/web/javascript/guide/control_flow_and_error_handling/index.html b/files/en-us/web/javascript/guide/control_flow_and_error_handling/index.html index c96acca8b536b2b..893cd1629a4abcf 100644 --- a/files/en-us/web/javascript/guide/control_flow_and_error_handling/index.html +++ b/files/en-us/web/javascript/guide/control_flow_and_error_handling/index.html @@ -55,7 +55,7 @@Here, { x++; }
is the block statement.
Important: JavaScript before ECMAScript2015 (6th edition) +
Note: JavaScript before ECMAScript2015 (6th edition)
does not have block scope! In older JavaScript, variables introduced
within a block are scoped to the containing function or script, and the effects of
setting them persist beyond the block itself. In other words, block statements do
@@ -181,7 +181,7 @@ Falsy values
conditional statement.
Caution: Do not confuse the primitive boolean values +
Note: Do not confuse the primitive boolean values
true
and false
with the true and false values of the
{{jsxref("Boolean")}} object!
catch
blockBest practice: When logging errors to the console inside +
Note: When logging errors to the console inside
a catch
block, using console.error()
rather than
console.log()
is advised for debugging. It formats the message as an
error, and adds it to the list of error messages generated by the page.
JavaScript follows a similar model, but does not have a class definition separate from the constructor. Instead, you define a constructor function to create objects with a particular initial set of properties and values. Any JavaScript function can be used as a constructor. You use the new
operator with a constructor function to create a new object.
Note that ECMAScript 2015 introduces a class declaration:
+Note: ECMAScript 2015 introduces a class declaration:
JavaScript classes, introduced in ECMAScript 2015, are primarily syntactical sugar over JavaScript's existing prototype-based inheritance. The class syntax does not introduce a new object-oriented inheritance model to JavaScript.
diff --git a/files/en-us/web/javascript/guide/functions/index.html b/files/en-us/web/javascript/guide/functions/index.html index 8a3d0ee783ad573..ba0d8a15421eaa5 100644 --- a/files/en-us/web/javascript/guide/functions/index.html +++ b/files/en-us/web/javascript/guide/functions/index.html @@ -470,7 +470,7 @@Closures
-Caution: There are a number of pitfalls to watch out for when using closures!
+Note: There are a number of pitfalls to watch out for when using closures!
If an enclosed function defines a variable with the same name as a variable in the outer scope, then there is no way to refer to the variable in the outer scope again. (The inner scope variable "overrides" the outer one, until the program exits the inner scope.)
diff --git a/files/en-us/web/javascript/guide/grammar_and_types/index.html b/files/en-us/web/javascript/guide/grammar_and_types/index.html index 086ae5dd7a910b0..c1b9d1c0b99a428 100644 --- a/files/en-us/web/javascript/guide/grammar_and_types/index.html +++ b/files/en-us/web/javascript/guide/grammar_and_types/index.html @@ -25,7 +25,7 @@Basics
A semicolon is not necessary after a statement if it is written on its own line. But if more than one statement on a line is desired, then they must be separated by semicolons.
-ECMAScript also has rules for automatic insertion of semicolons (ASI) to end statements. (For more information, see the detailed reference about JavaScript's lexical grammar.)
+Note: ECMAScript also has rules for automatic insertion of semicolons (ASI) to end statements. (For more information, see the detailed reference about JavaScript's lexical grammar.)
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.
@@ -48,7 +48,7 @@Comments
Comments behave like whitespace, and are discarded during script execution.
-@@ -347,7 +347,7 @@Note: You might also see a third type of comment syntax at the start of some JavaScript files, which looks something like this:
+#!/usr/bin/env node
.Note: You might also see a third type of comment syntax at the start of some JavaScript files, which looks something like this:
#!/usr/bin/env node
.This is called hashbang comment syntax, and is a special comment used to specify the path to a particular JavaScript engine that should execute the script. See Hashbang comments for more details.
Converting strings to numbers
parseInt
only returns whole numbers, so its use is diminished for decimals.-Additionally, a best practice for
+parseInt
is to always include the radix parameter. The radix parameter is used to specify which numerical system is to be used.Note: Additionally, a best practice for
parseInt
is to always include the radix parameter. The radix parameter is used to specify which numerical system is to be used.parseInt('101', 2) // 5@@ -382,7 +382,7 @@Array literals
-Note : An array literal is a type of object initializer. See Using Object Initializers.
+Note: An array literal is a type of object initializer. See Using Object Initializers.
If an array is created using a literal in a top-level script, JavaScript interprets the array each time it evaluates the expression containing the array literal. In addition, a literal used in a function is created each time the function is called.
@@ -411,7 +411,7 @@Extra commas in array literals
In the following example, the
length
of the array is three. There is nomyList[3]
. All other commas in the list indicate a new element.-Note : Trailing commas can create errors in older browser versions and it is a best practice to remove them.
+Note: Trailing commas can create errors in older browser versions and it is a best practice to remove them.
let myList = ['home', , 'school', ]; @@ -436,7 +436,7 @@Boolean literals
The Boolean type has two literal values:
true
andfalse
.-@@ -495,7 +495,7 @@Be careful: Do not confuse the primitive Boolean values
+true
andfalse
with the true and false values of the {{jsxref("Boolean")}} object.Note: Do not confuse the primitive Boolean values
true
andfalse
with the true and false values of the {{jsxref("Boolean")}} object.The Boolean object is a wrapper around the primitive Boolean data type. See {{jsxref("Boolean")}} for more information.
Object literals
An object literal is a list of zero or more pairs of property names and associated values of an object, enclosed in curly braces (
{}
).-Do not use an object literal at the beginning of a statement! This will lead to an error (or not behave as you expect), because the
+{
will be interpreted as the beginning of a block.Note: Do not use an object literal at the beginning of a statement! This will lead to an error (or not behave as you expect), because the
{
will be interpreted as the beginning of a block.The following is an example of an object literal. The first element of the
diff --git a/files/en-us/web/javascript/guide/keyed_collections/index.html b/files/en-us/web/javascript/guide/keyed_collections/index.html index 5515c7c70c46470..56ec6fc5754d6d7 100644 --- a/files/en-us/web/javascript/guide/keyed_collections/index.html +++ b/files/en-us/web/javascript/guide/keyed_collections/index.html @@ -114,8 +114,7 @@car
object defines a property,myCar
, and assigns to it a new string, "Saturn
"; the second element, thegetCar
property, is immediately assigned the result of invoking the function(carTypes("Honda"))
; the third element, thespecial
property, uses an existing variable (sales
).Converting between Array and Set
You can create an {{jsxref("Array")}} from a Set using {{jsxref("Array.from")}} or the spread syntax. Also, the
Set
constructor accepts anArray
to convert in the other direction.-Note
-Remember that
+Set
objects store unique values—so any duplicate elements from an Array are deleted when converting!Note:
Set
objects store unique values—so any duplicate elements from an Array are deleted when converting!Array.from(mySet); diff --git a/files/en-us/web/javascript/guide/regular_expressions/assertions/index.html b/files/en-us/web/javascript/guide/regular_expressions/assertions/index.html index 7500eec8f9f8237..287d53628916632 100644 --- a/files/en-us/web/javascript/guide/regular_expressions/assertions/index.html +++ b/files/en-us/web/javascript/guide/regular_expressions/assertions/index.html @@ -34,7 +34,7 @@Boundary-type assertions
Matches the beginning of input. If the multiline flag is set to true, also matches immediately after a line break character. For example,
/^A/
does not match the "A" in "an A", but does match the first "A" in "An A".-@@ -73,7 +73,7 @@This character has a different meaning when it appears at the start of a group.
+Note: This character has a different meaning when it appears at the start of a group.
Boundary-type assertions
Other assertions
-Note: The
+?
character may also be used as a quantifier.Note: The
?
character may also be used as a quantifier.