Skip to content

Commit c16a0ee

Browse files
authored
Reorganize JS numbers/dates/strings guides (#37563)
* Reorganize JS numbers/dates/strings guides * Update jssidebar.yaml
1 parent 93eda4e commit c16a0ee

File tree

19 files changed

+355
-468
lines changed

19 files changed

+355
-468
lines changed

files/en-us/_redirects.txt

+2
Original file line numberDiff line numberDiff line change
@@ -12791,6 +12791,7 @@
1279112791
/en-US/docs/Web/JavaScript/Guide/Inheritance_Revisited /en-US/docs/Web/JavaScript/Inheritance_and_the_prototype_chain
1279212792
/en-US/docs/Web/JavaScript/Guide/Inheritance_and_the_prototype_chain /en-US/docs/Web/JavaScript/Inheritance_and_the_prototype_chain
1279312793
/en-US/docs/Web/JavaScript/Guide/JavaScript_Overview /en-US/docs/Web/JavaScript/Guide/Introduction
12794+
/en-US/docs/Web/JavaScript/Guide/Numbers_and_dates /en-US/docs/Web/JavaScript/Guide/Numbers_and_strings
1279412795
/en-US/docs/Web/JavaScript/Guide/Obsolete_Pages /en-US/docs/Web/JavaScript/Guide
1279512796
/en-US/docs/Web/JavaScript/Guide/Obsolete_Pages/Block_Statement /en-US/docs/Web/JavaScript/Guide/Control_flow_and_error_handling
1279612797
/en-US/docs/Web/JavaScript/Guide/Obsolete_Pages/Calling_Functions /en-US/docs/Web/JavaScript/Guide/Functions
@@ -12876,6 +12877,7 @@
1287612877
/en-US/docs/Web/JavaScript/Guide/Regular_expressions/Unicode_property_escapes /en-US/docs/Web/JavaScript/Reference/Regular_expressions/Unicode_character_class_escape
1287712878
/en-US/docs/Web/JavaScript/Guide/Sameness /en-US/docs/Web/JavaScript/Equality_comparisons_and_sameness
1287812879
/en-US/docs/Web/JavaScript/Guide/Statements /en-US/docs/Web/JavaScript/Guide/Control_flow_and_error_handling
12880+
/en-US/docs/Web/JavaScript/Guide/Text_formatting /en-US/docs/Web/JavaScript/Guide/Numbers_and_strings
1287912881
/en-US/docs/Web/JavaScript/Guide/The_Iterator_protocol /en-US/docs/Web/JavaScript/Reference/Iteration_protocols
1288012882
/en-US/docs/Web/JavaScript/Guide/The_legacy_Iterator_protocol /en-US/docs/Web/JavaScript/Reference/Deprecated_and_obsolete_features
1288112883
/en-US/docs/Web/JavaScript/Guide/Using_native_JSON /en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON

files/en-us/_wikihistory.json

+1-26
Original file line numberDiff line numberDiff line change
@@ -102176,7 +102176,7 @@
102176102176
"douglasnaphas"
102177102177
]
102178102178
},
102179-
"Web/JavaScript/Guide/Numbers_and_dates": {
102179+
"Web/JavaScript/Guide/Numbers_and_strings": {
102180102180
"modified": "2020-11-14T07:27:01.088Z",
102181102181
"contributors": [
102182102182
"mfuji09",
@@ -102422,31 +102422,6 @@
102422102422
"jpmedley"
102423102423
]
102424102424
},
102425-
"Web/JavaScript/Guide/Text_formatting": {
102426-
"modified": "2020-05-25T10:48:56.137Z",
102427-
"contributors": [
102428-
"fscholz",
102429-
"wbamberg",
102430-
"bma",
102431-
"alattalatta",
102432-
"vriojtg",
102433-
"sbfraser01",
102434-
"chrisdavidmills",
102435-
"JigneshMistry",
102436-
"stephaniehobson",
102437-
"SphinxKnight",
102438-
"amir77ameri",
102439-
"ThomasEugeneBishop",
102440-
"nmve",
102441-
"kdex",
102442-
"Jeremie",
102443-
"danielinux7",
102444-
"gportioli",
102445-
"xfq",
102446-
"mahzaib",
102447-
"kscarfone"
102448-
]
102449-
},
102450102425
"Web/JavaScript/Guide/Typed_arrays": {
102451102426
"modified": "2020-10-15T21:04:01.905Z",
102452102427
"contributors": [

files/en-us/learn_web_development/core/scripting/math/index.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ In the next article, we'll explore text and how JavaScript allows us to manipula
456456

457457
## See also
458458

459-
- [Numbers and dates](/en-US/docs/Web/JavaScript/Guide/Numbers_and_dates)
459+
- [Numbers and strings](/en-US/docs/Web/JavaScript/Guide/Numbers_and_strings)
460460
- [Expressions and operators](/en-US/docs/Web/JavaScript/Guide/Expressions_and_operators)
461461

462462
{{PreviousMenuNext("Learn_web_development/Core/Scripting/Variables", "Learn_web_development/Core/Scripting/Strings", "Learn_web_development/Core/Scripting")}}

files/en-us/web/html/date_and_time_formats/index.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,6 @@ Why worry about the Y10K problem if it is going to happen many centuries after y
430430
- {{HTMLElement("input")}}
431431
- {{HTMLElement("ins")}} and {{HTMLElement("del")}}: see the `datetime` attribute, which specifies either a date or a local date and time at which the content was inserted or deleted
432432
- [The ISO 8601 specification](https://www.iso.org/iso-8601-date-and-time-format.html)
433-
- [Numbers and Dates](/en-US/docs/Web/JavaScript/Guide/Numbers_and_dates) in the [JavaScript Guide](/en-US/docs/Web/JavaScript/Guide)
433+
- [Representing dates & times](/en-US/docs/Web/JavaScript/Guide/Representing_dates_times) in the [JavaScript Guide](/en-US/docs/Web/JavaScript/Guide)
434434
- The JavaScript {{jsxref("Date")}} object
435435
- The [`Intl.DateTimeFormat`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat) object for formatting dates and times for a given locale

files/en-us/web/javascript/guide/expressions_and_operators/index.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ slug: Web/JavaScript/Guide/Expressions_and_operators
44
page-type: guide
55
---
66

7-
{{jsSidebar("JavaScript Guide")}} {{PreviousNext("Web/JavaScript/Guide/Functions", "Web/JavaScript/Guide/Numbers_and_dates")}}
7+
{{jsSidebar("JavaScript Guide")}} {{PreviousNext("Web/JavaScript/Guide/Functions", "Web/JavaScript/Guide/Numbers_and_strings")}}
88

99
This chapter describes JavaScript's expressions and operators, including assignment, comparison, arithmetic, bitwise, logical, string, ternary and more.
1010

@@ -1148,4 +1148,4 @@ super(args); // calls the parent constructor.
11481148
super.functionOnParent(args);
11491149
```
11501150
1151-
{{PreviousNext("Web/JavaScript/Guide/Functions", "Web/JavaScript/Guide/Numbers_and_dates")}}
1151+
{{PreviousNext("Web/JavaScript/Guide/Functions", "Web/JavaScript/Guide/Numbers_and_strings")}}

files/en-us/web/javascript/guide/index.md

+30-13
Original file line numberDiff line numberDiff line change
@@ -73,24 +73,33 @@ Overview: [Expressions and operators](/en-US/docs/Web/JavaScript/Guide/Expressio
7373
- [Bitwise](/en-US/docs/Web/JavaScript/Guide/Expressions_and_operators#bitwise_operators) & [logical operators](/en-US/docs/Web/JavaScript/Guide/Expressions_and_operators#logical_operators)
7474
- [Conditional (ternary) operator](</en-US/docs/Web/JavaScript/Guide/Expressions_and_operators#conditional_(ternary)_operator>)
7575

76-
## Numbers and dates
76+
## Numbers and strings
7777

78-
Overview: [Numbers and dates](/en-US/docs/Web/JavaScript/Guide/Numbers_and_dates)
78+
Overview: [Numbers and strings](/en-US/docs/Web/JavaScript/Guide/Numbers_and_strings)
7979

80-
- [Number literals](/en-US/docs/Web/JavaScript/Guide/Numbers_and_dates#numbers)
81-
- [`Number` object](/en-US/docs/Web/JavaScript/Guide/Numbers_and_dates#number_object)
82-
- [`Math` object](/en-US/docs/Web/JavaScript/Guide/Numbers_and_dates#math_object)
83-
- [`Date` object](/en-US/docs/Web/JavaScript/Guide/Numbers_and_dates#date_object)
80+
- [Numbers](/en-US/docs/Web/JavaScript/Guide/Numbers_and_strings#numbers)
81+
- [`Number` object](/en-US/docs/Web/JavaScript/Guide/Numbers_and_strings#number_object)
82+
- [`Math` object](/en-US/docs/Web/JavaScript/Guide/Numbers_and_strings#math_object)
83+
- [Strings](/en-US/docs/Web/JavaScript/Guide/Numbers_and_strings#strings)
84+
- [`String` object](/en-US/docs/Web/JavaScript/Guide/Numbers_and_strings#string_object)
85+
- [Template literals](/en-US/docs/Web/JavaScript/Guide/Numbers_and_strings#template_literals)
8486

85-
## Text formatting
87+
## Representing dates & times
8688

87-
Overview: [Text formatting](/en-US/docs/Web/JavaScript/Guide/Text_formatting)
89+
Overview: [Representing dates & times](/en-US/docs/Web/JavaScript/Guide/Representing_dates_times)
8890

89-
- [String literals](/en-US/docs/Web/JavaScript/Guide/Text_formatting#string_literals)
90-
- [`String` object](/en-US/docs/Web/JavaScript/Guide/Text_formatting#string_objects)
91-
- [Template literals](/en-US/docs/Web/JavaScript/Guide/Text_formatting#multi-line_template_literals)
92-
- [Internationalization](/en-US/docs/Web/JavaScript/Guide/Text_formatting#internationalization)
93-
- [Regular Expressions](/en-US/docs/Web/JavaScript/Guide/Regular_expressions)
91+
- [`Date` object](/en-US/docs/Web/JavaScript/Guide/Representing_dates_times#date_object)
92+
93+
## Regular expressions
94+
95+
Overview: [Regular expressions](/en-US/docs/Web/JavaScript/Guide/Regular_expressions)
96+
97+
- [Creating a regular expression](/en-US/docs/Web/JavaScript/Guide/Regular_expressions#creating_a_regular_expression)
98+
- [Writing a regular expression pattern](/en-US/docs/Web/JavaScript/Guide/Regular_expressions#writing_a_regular_expression_pattern)
99+
- [Assertions](/en-US/docs/Web/JavaScript/Guide/Regular_expressions/Assertions)
100+
- [Character classes](/en-US/docs/Web/JavaScript/Guide/Regular_expressions/Character_classes)
101+
- [Groups and backreferences](/en-US/docs/Web/JavaScript/Guide/Regular_expressions/Groups_and_backreferences)
102+
- [Quantifiers](/en-US/docs/Web/JavaScript/Guide/Regular_expressions/Quantifiers)
94103

95104
## Indexed collections
96105

@@ -145,6 +154,14 @@ Overview: [Iterators and generators](/en-US/docs/Web/JavaScript/Guide/Iterators_
145154
- [Iterables](/en-US/docs/Web/JavaScript/Guide/Iterators_and_generators#iterables)
146155
- [Generators](/en-US/docs/Web/JavaScript/Guide/Iterators_and_generators#generator_functions)
147156

157+
## Internationalization
158+
159+
Overview: [Internationalization](/en-US/docs/Web/JavaScript/Guide/Internationalization)
160+
161+
- [Date and time formatting](/en-US/docs/Web/JavaScript/Guide/Internationalization#date_and_time_formatting)
162+
- [Number formatting](/en-US/docs/Web/JavaScript/Guide/Internationalization#number_formatting)
163+
- [Collation](/en-US/docs/Web/JavaScript/Guide/Internationalization#collation)
164+
148165
## Meta programming
149166

150167
Overview: [Meta programming](/en-US/docs/Web/JavaScript/Guide/Meta_programming)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
---
2+
title: Internationalization
3+
slug: Web/JavaScript/Guide/Internationalization
4+
page-type: guide
5+
---
6+
7+
{{jsSidebar("JavaScript Guide")}} {{PreviousNext("Web/JavaScript/Guide/Iterators_and_generators", "Web/JavaScript/Guide/Meta_programming")}}
8+
9+
The {{jsxref("Intl")}} object is the namespace for the ECMAScript Internationalization API, which provides a wide range of locale- and culture-sensitive data and operations.
10+
11+
## Date and time formatting
12+
13+
The {{jsxref("Intl.DateTimeFormat")}} object is useful for formatting date and time. The following formats a date for English as used in the United States. (The result is different in another time zone.)
14+
15+
```js
16+
// July 17, 2014 00:00:00 UTC:
17+
const july172014 = new Date("2014-07-17");
18+
19+
const options = {
20+
year: "2-digit",
21+
month: "2-digit",
22+
day: "2-digit",
23+
hour: "2-digit",
24+
minute: "2-digit",
25+
timeZoneName: "short",
26+
};
27+
const americanDateTime = new Intl.DateTimeFormat("en-US", options).format;
28+
29+
// Local timezone vary depending on your settings
30+
// In CEST, logs: 07/17/14, 02:00 AM GMT+2
31+
// In PDT, logs: 07/16/14, 05:00 PM GMT-7
32+
console.log(americanDateTime(july172014));
33+
```
34+
35+
## Number formatting
36+
37+
The {{jsxref("Intl.NumberFormat")}} object is useful for formatting numbers, for example currencies.
38+
39+
```js
40+
const gasPrice = new Intl.NumberFormat("en-US", {
41+
style: "currency",
42+
currency: "USD",
43+
minimumFractionDigits: 3,
44+
});
45+
46+
console.log(gasPrice.format(5.259)); // $5.259
47+
48+
const hanDecimalRMBInChina = new Intl.NumberFormat("zh-CN-u-nu-hanidec", {
49+
style: "currency",
50+
currency: "CNY",
51+
});
52+
53+
console.log(hanDecimalRMBInChina.format(1314.25)); // ¥ 一,三一四.二五
54+
```
55+
56+
## Collation
57+
58+
The {{jsxref("Intl.Collator")}} object is useful for comparing and sorting strings.
59+
60+
For example, there are actually two different sort orders in German, _phonebook_ and _dictionary_. Phonebook sort emphasizes sound, and it's as if "ä", "ö", and so on were expanded to "ae", "oe", and so on prior to sorting.
61+
62+
```js
63+
const names = ["Hochberg", "Hönigswald", "Holzman"];
64+
65+
const germanPhonebook = new Intl.Collator("de-DE-u-co-phonebk");
66+
67+
// as if sorting ["Hochberg", "Hoenigswald", "Holzman"]:
68+
console.log(names.sort(germanPhonebook.compare).join(", "));
69+
// "Hochberg, Hönigswald, Holzman"
70+
```
71+
72+
Some German words conjugate with extra umlauts, so in dictionaries it's sensible to order ignoring umlauts (except when ordering words differing _only_ by umlauts: _schon_ before _schön_).
73+
74+
```js
75+
const germanDictionary = new Intl.Collator("de-DE-u-co-dict");
76+
77+
// as if sorting ["Hochberg", "Honigswald", "Holzman"]:
78+
console.log(names.sort(germanDictionary.compare).join(", "));
79+
// "Hochberg, Holzman, Hönigswald"
80+
```
81+
82+
For more information about the {{jsxref("Intl")}} API, see also [Introducing the JavaScript Internationalization API](https://hacks.mozilla.org/2014/12/introducing-the-javascript-internationalization-api/).
83+
84+
{{PreviousNext("Web/JavaScript/Guide/Iterators_and_generators", "Web/JavaScript/Guide/Meta_programming")}}

files/en-us/web/javascript/guide/iterators_and_generators/index.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ slug: Web/JavaScript/Guide/Iterators_and_generators
44
page-type: guide
55
---
66

7-
{{jsSidebar("JavaScript Guide")}} {{PreviousNext("Web/JavaScript/Guide/Typed_arrays", "Web/JavaScript/Guide/Meta_programming")}}
7+
{{jsSidebar("JavaScript Guide")}} {{PreviousNext("Web/JavaScript/Guide/Typed_arrays", "Web/JavaScript/Guide/Internationalization")}}
88

99
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.
1010

@@ -234,4 +234,4 @@ If the exception is not caught from within the generator, it will propagate up t
234234

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

237-
{{PreviousNext("Web/JavaScript/Guide/Typed_arrays", "Web/JavaScript/Guide/Meta_programming")}}
237+
{{PreviousNext("Web/JavaScript/Guide/Typed_arrays", "Web/JavaScript/Guide/Internationalization")}}

files/en-us/web/javascript/guide/meta_programming/index.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ slug: Web/JavaScript/Guide/Meta_programming
44
page-type: guide
55
---
66

7-
{{jsSidebar("JavaScript Guide")}}{{PreviousNext("Web/JavaScript/Guide/Iterators_and_generators", "Web/JavaScript/Guide/Modules")}}
7+
{{jsSidebar("JavaScript Guide")}}{{PreviousNext("Web/JavaScript/Guide/Internationalization", "Web/JavaScript/Guide/Modules")}}
88

99
The {{jsxref("Proxy")}} and {{jsxref("Reflect")}} objects allow you to intercept and define custom behavior for fundamental language operations (e.g. property lookup, assignment, enumeration, function invocation, etc.). With the help of these two objects you are able to program at the meta level of JavaScript.
1010

@@ -282,4 +282,4 @@ if (Reflect.defineProperty(target, property, attributes)) {
282282
}
283283
```
284284

285-
{{PreviousNext("Web/JavaScript/Guide/Iterators_and_generators", "Web/JavaScript/Guide/Modules")}}
285+
{{PreviousNext("Web/JavaScript/Guide/Internationalization", "Web/JavaScript/Guide/Modules")}}

0 commit comments

Comments
 (0)