diff --git a/1-js/05-data-types/03-string/article.md b/1-js/05-data-types/03-string/article.md index ebfda974..b7bb907e 100644 --- a/1-js/05-data-types/03-string/article.md +++ b/1-js/05-data-types/03-string/article.md @@ -43,7 +43,6 @@ Looks natural, right? But single or double quotes do not work this way. If we use them and try to use multiple lines, there'll be an error: - ```js run let guestList = "Guests: // Error: Unexpected token ILLEGAL * John"; @@ -53,7 +52,6 @@ Single and double quotes come from ancient times of language creation when the n Backticks also allow us to specify a "template function" before the first backtick. The syntax is: func`string`. The function `func` is called automatically, receives the string and embedded expressions and can process them. You can read more about it in the [docs](mdn:/JavaScript/Reference/Template_literals#Tagged_template_literals). This is called "tagged templates". This feature makes it easier to wrap strings into custom templating or other functionality, but it is rarely used. - ## Special characters It is still possible to create multiline strings with single quotes by using a so-called "newline character", written as `\n`, which denotes a line break: @@ -130,7 +128,6 @@ alert( `The backslash: \\` ); // The backslash: \ ## String length - The `length` property has the string length: ```js run @@ -252,10 +249,8 @@ let str = 'Widget with id'; alert( str.indexOf('id', 2) ) // 12 ``` - If we're interested in all occurrences, we can run `indexOf` in a loop. Every new call is made with the position after the previous match: - ```js run let str = 'As sly as a fox, as strong as an ox'; @@ -411,7 +406,6 @@ There are 3 methods in JavaScript to get a substring: `substring`, `substr` and alert( str.slice(-4, -1) ); // gif ``` - `str.substring(start [, end])` : Returns the part of the string *between* `start` and `end`. @@ -419,7 +413,6 @@ There are 3 methods in JavaScript to get a substring: `substring`, `substr` and For instance: - ```js run let str = "st*!*ring*/!*ify"; @@ -435,7 +428,6 @@ There are 3 methods in JavaScript to get a substring: `substring`, `substr` and Negative arguments are (unlike slice) not supported, they are treated as `0`. - `str.substr(start [, length])` : Returns the part of the string from `start`, with the given `length`. @@ -461,7 +453,6 @@ Let's recap these methods to avoid any confusion: | `substring(start, end)` | between `start` and `end` | negative values mean `0` | | `substr(start, length)` | from `start` get `length` characters | allows negative `start` | - ```smart header="Which one to choose?" All of them can do the job. Formally, `substr` has a minor drawback: it is described not in the core JavaScript specification, but in Annex B, which covers browser-only features that exist mainly for historical reasons. So, non-browser environments may fail to support it. But in practice it works everywhere. @@ -537,7 +528,6 @@ The characters are compared by their numeric code. The greater code means that t - All lowercase letters go after uppercase letters because their codes are greater. - Some letters like `Ö` stand apart from the main alphabet. Here, it's code is greater than anything from `a` to `z`. - ### Correct comparisons The "right" algorithm to do string comparisons is more complex than it may seem, because alphabets are different for different languages. @@ -667,7 +657,6 @@ In reality, this is not always the case. The reason being that the symbol `Ṩ` If you want to learn more about normalization rules and variants -- they are described in the appendix of the Unicode standard: [Unicode Normalization Forms](http://www.unicode.org/reports/tr15/), but for most practical purposes the information from this section is enough. - ## Summary - There are 3 types of quotes. Backticks allow a string to span multiple lines and embed expressions `${…}`.