Skip to content

Commit

Permalink
Reorganize JS numbers/dates/strings guides
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh-Cena committed Jan 8, 2025
1 parent 9a7e014 commit 868ef85
Show file tree
Hide file tree
Showing 19 changed files with 354 additions and 467 deletions.
2 changes: 2 additions & 0 deletions files/en-us/_redirects.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12791,6 +12791,7 @@
/en-US/docs/Web/JavaScript/Guide/Inheritance_Revisited /en-US/docs/Web/JavaScript/Inheritance_and_the_prototype_chain
/en-US/docs/Web/JavaScript/Guide/Inheritance_and_the_prototype_chain /en-US/docs/Web/JavaScript/Inheritance_and_the_prototype_chain
/en-US/docs/Web/JavaScript/Guide/JavaScript_Overview /en-US/docs/Web/JavaScript/Guide/Introduction
/en-US/docs/Web/JavaScript/Guide/Numbers_and_dates /en-US/docs/Web/JavaScript/Guide/Numbers_and_strings
/en-US/docs/Web/JavaScript/Guide/Obsolete_Pages /en-US/docs/Web/JavaScript/Guide
/en-US/docs/Web/JavaScript/Guide/Obsolete_Pages/Block_Statement /en-US/docs/Web/JavaScript/Guide/Control_flow_and_error_handling
/en-US/docs/Web/JavaScript/Guide/Obsolete_Pages/Calling_Functions /en-US/docs/Web/JavaScript/Guide/Functions
Expand Down Expand Up @@ -12876,6 +12877,7 @@
/en-US/docs/Web/JavaScript/Guide/Regular_expressions/Unicode_property_escapes /en-US/docs/Web/JavaScript/Reference/Regular_expressions/Unicode_character_class_escape
/en-US/docs/Web/JavaScript/Guide/Sameness /en-US/docs/Web/JavaScript/Equality_comparisons_and_sameness
/en-US/docs/Web/JavaScript/Guide/Statements /en-US/docs/Web/JavaScript/Guide/Control_flow_and_error_handling
/en-US/docs/Web/JavaScript/Guide/Text_formatting /en-US/docs/Web/JavaScript/Guide/Numbers_and_strings
/en-US/docs/Web/JavaScript/Guide/The_Iterator_protocol /en-US/docs/Web/JavaScript/Reference/Iteration_protocols
/en-US/docs/Web/JavaScript/Guide/The_legacy_Iterator_protocol /en-US/docs/Web/JavaScript/Reference/Deprecated_and_obsolete_features
/en-US/docs/Web/JavaScript/Guide/Using_native_JSON /en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON
Expand Down
27 changes: 1 addition & 26 deletions files/en-us/_wikihistory.json
Original file line number Diff line number Diff line change
Expand Up @@ -102176,7 +102176,7 @@
"douglasnaphas"
]
},
"Web/JavaScript/Guide/Numbers_and_dates": {
"Web/JavaScript/Guide/Numbers_and_strings": {
"modified": "2020-11-14T07:27:01.088Z",
"contributors": [
"mfuji09",
Expand Down Expand Up @@ -102422,31 +102422,6 @@
"jpmedley"
]
},
"Web/JavaScript/Guide/Text_formatting": {
"modified": "2020-05-25T10:48:56.137Z",
"contributors": [
"fscholz",
"wbamberg",
"bma",
"alattalatta",
"vriojtg",
"sbfraser01",
"chrisdavidmills",
"JigneshMistry",
"stephaniehobson",
"SphinxKnight",
"amir77ameri",
"ThomasEugeneBishop",
"nmve",
"kdex",
"Jeremie",
"danielinux7",
"gportioli",
"xfq",
"mahzaib",
"kscarfone"
]
},
"Web/JavaScript/Guide/Typed_arrays": {
"modified": "2020-10-15T21:04:01.905Z",
"contributors": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ In the next article, we'll explore text and how JavaScript allows us to manipula

## See also

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

{{PreviousMenuNext("Learn_web_development/Core/Scripting/Variables", "Learn_web_development/Core/Scripting/Strings", "Learn_web_development/Core/Scripting")}}
2 changes: 1 addition & 1 deletion files/en-us/web/html/date_and_time_formats/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,6 @@ Why worry about the Y10K problem if it is going to happen many centuries after y
- {{HTMLElement("input")}}
- {{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
- [The ISO 8601 specification](https://www.iso.org/iso-8601-date-and-time-format.html)
- [Numbers and Dates](/en-US/docs/Web/JavaScript/Guide/Numbers_and_dates) in the [JavaScript Guide](/en-US/docs/Web/JavaScript/Guide)
- [Representing dates & times](/en-US/docs/Web/JavaScript/Guide/Representing_dates_times) in the [JavaScript Guide](/en-US/docs/Web/JavaScript/Guide)
- The JavaScript {{jsxref("Date")}} object
- The [`Intl.DateTimeFormat`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat) object for formatting dates and times for a given locale
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ slug: Web/JavaScript/Guide/Expressions_and_operators
page-type: guide
---

{{jsSidebar("JavaScript Guide")}} {{PreviousNext("Web/JavaScript/Guide/Functions", "Web/JavaScript/Guide/Numbers_and_dates")}}
{{jsSidebar("JavaScript Guide")}} {{PreviousNext("Web/JavaScript/Guide/Functions", "Web/JavaScript/Guide/Numbers_and_strings")}}

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

Expand Down Expand Up @@ -1148,4 +1148,4 @@ super(args); // calls the parent constructor.
super.functionOnParent(args);
```
{{PreviousNext("Web/JavaScript/Guide/Functions", "Web/JavaScript/Guide/Numbers_and_dates")}}
{{PreviousNext("Web/JavaScript/Guide/Functions", "Web/JavaScript/Guide/Numbers_and_strings")}}
43 changes: 30 additions & 13 deletions files/en-us/web/javascript/guide/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,24 +73,33 @@ Overview: [Expressions and operators](/en-US/docs/Web/JavaScript/Guide/Expressio
- [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)
- [Conditional (ternary) operator](</en-US/docs/Web/JavaScript/Guide/Expressions_and_operators#conditional_(ternary)_operator>)

## Numbers and dates
## Numbers and strings

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

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

## Text formatting
## Representing dates & times

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

- [String literals](/en-US/docs/Web/JavaScript/Guide/Text_formatting#string_literals)
- [`String` object](/en-US/docs/Web/JavaScript/Guide/Text_formatting#string_objects)
- [Template literals](/en-US/docs/Web/JavaScript/Guide/Text_formatting#multi-line_template_literals)
- [Internationalization](/en-US/docs/Web/JavaScript/Guide/Text_formatting#internationalization)
- [Regular Expressions](/en-US/docs/Web/JavaScript/Guide/Regular_expressions)
- [`Date` object](/en-US/docs/Web/JavaScript/Guide/Representing_dates_times#date_object)

## Regular expressions

Overview: [Regular expressions](/en-US/docs/Web/JavaScript/Guide/Regular_expressions)

- [Creating a regular expression](/en-US/docs/Web/JavaScript/Guide/Regular_expressions#creating_a_regular_expression)
- [Writing a regular expression pattern](/en-US/docs/Web/JavaScript/Guide/Regular_expressions#writing_a_regular_expression_pattern)
- [Assertions](/en-US/docs/Web/JavaScript/Guide/Regular_expressions/Assertions)
- [Character classes](/en-US/docs/Web/JavaScript/Guide/Regular_expressions/Character_classes)
- [Groups and backreferences](/en-US/docs/Web/JavaScript/Guide/Regular_expressions/Groups_and_backreferences)
- [Quantifiers](/en-US/docs/Web/JavaScript/Guide/Regular_expressions/Quantifiers)

## Indexed collections

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

## Internationalization

Overview: [Internationalization](/en-US/docs/Web/JavaScript/Guide/Internationalization)

- [Date and time formatting](/en-US/docs/Web/JavaScript/Guide/Internationalization#date_and_time_formatting)
- [Number formatting](/en-US/docs/Web/JavaScript/Guide/Internationalization#number_formatting)
- [Collation](/en-US/docs/Web/JavaScript/Guide/Internationalization#collation)

## Meta programming

Overview: [Meta programming](/en-US/docs/Web/JavaScript/Guide/Meta_programming)
Expand Down
84 changes: 84 additions & 0 deletions files/en-us/web/javascript/guide/internationalization/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
---
title: Internationalization
slug: Web/JavaScript/Guide/Internationalization
page-type: guide
---

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

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.

## Date and time formatting

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.)

```js
// July 17, 2014 00:00:00 UTC:
const july172014 = new Date("2014-07-17");

const options = {
year: "2-digit",
month: "2-digit",
day: "2-digit",
hour: "2-digit",
minute: "2-digit",
timeZoneName: "short",
};
const americanDateTime = new Intl.DateTimeFormat("en-US", options).format;

// Local timezone vary depending on your settings
// In CEST, logs: 07/17/14, 02:00 AM GMT+2
// In PDT, logs: 07/16/14, 05:00 PM GMT-7
console.log(americanDateTime(july172014));
```

## Number formatting

The {{jsxref("Intl.NumberFormat")}} object is useful for formatting numbers, for example currencies.

```js
const gasPrice = new Intl.NumberFormat("en-US", {
style: "currency",
currency: "USD",
minimumFractionDigits: 3,
});

console.log(gasPrice.format(5.259)); // $5.259

const hanDecimalRMBInChina = new Intl.NumberFormat("zh-CN-u-nu-hanidec", {
style: "currency",
currency: "CNY",
});

console.log(hanDecimalRMBInChina.format(1314.25)); // ¥ 一,三一四.二五
```

## Collation

The {{jsxref("Intl.Collator")}} object is useful for comparing and sorting strings.

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.

```js
const names = ["Hochberg", "Hönigswald", "Holzman"];

const germanPhonebook = new Intl.Collator("de-DE-u-co-phonebk");

// as if sorting ["Hochberg", "Hoenigswald", "Holzman"]:
console.log(names.sort(germanPhonebook.compare).join(", "));
// "Hochberg, Hönigswald, Holzman"
```

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_).

```js
const germanDictionary = new Intl.Collator("de-DE-u-co-dict");

// as if sorting ["Hochberg", "Honigswald", "Holzman"]:
console.log(names.sort(germanDictionary.compare).join(", "));
// "Hochberg, Holzman, Hönigswald"
```

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/).

{{PreviousNext("Web/JavaScript/Guide/Iterators_and_generators", "Web/JavaScript/Guide/Meta_programming")}}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ slug: Web/JavaScript/Guide/Iterators_and_generators
page-type: guide
---

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

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.

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

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")}}
{{PreviousNext("Web/JavaScript/Guide/Typed_arrays", "Web/JavaScript/Guide/Internationalization")}}
4 changes: 2 additions & 2 deletions files/en-us/web/javascript/guide/meta_programming/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ slug: Web/JavaScript/Guide/Meta_programming
page-type: guide
---

{{jsSidebar("JavaScript Guide")}}{{PreviousNext("Web/JavaScript/Guide/Iterators_and_generators", "Web/JavaScript/Guide/Modules")}}
{{jsSidebar("JavaScript Guide")}}{{PreviousNext("Web/JavaScript/Guide/Internationalization", "Web/JavaScript/Guide/Modules")}}

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.

Expand Down Expand Up @@ -282,4 +282,4 @@ if (Reflect.defineProperty(target, property, attributes)) {
}
```

{{PreviousNext("Web/JavaScript/Guide/Iterators_and_generators", "Web/JavaScript/Guide/Modules")}}
{{PreviousNext("Web/JavaScript/Guide/Internationalization", "Web/JavaScript/Guide/Modules")}}
Loading

0 comments on commit 868ef85

Please sign in to comment.