Skip to content

Commit d1dc1a6

Browse files
committed
Remove newlines
1 parent f30e0d4 commit d1dc1a6

File tree

1 file changed

+0
-11
lines changed

1 file changed

+0
-11
lines changed

1-js/05-data-types/03-string/article.md

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ Looks natural, right? But single or double quotes do not work this way.
4343

4444
If we use them and try to use multiple lines, there'll be an error:
4545

46-
4746
```js run
4847
let guestList = "Guests: // Error: Unexpected token ILLEGAL
4948
* John";
@@ -53,7 +52,6 @@ Single and double quotes come from ancient times of language creation when the n
5352

5453
Backticks also allow us to specify a "template function" before the first backtick. The syntax is: <code>func&#96;string&#96;</code>. 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.
5554

56-
5755
## Special characters
5856

5957
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: \
130128

131129
## String length
132130

133-
134131
The `length` property has the string length:
135132

136133
```js run
@@ -252,10 +249,8 @@ let str = 'Widget with id';
252249
alert( str.indexOf('id', 2) ) // 12
253250
```
254251

255-
256252
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:
257253

258-
259254
```js run
260255
let str = 'As sly as a fox, as strong as an ox';
261256

@@ -411,15 +406,13 @@ There are 3 methods in JavaScript to get a substring: `substring`, `substr` and
411406
alert( str.slice(-4, -1) ); // gif
412407
```
413408

414-
415409
`str.substring(start [, end])`
416410
: Returns the part of the string *between* `start` and `end`.
417411

418412
This is almost the same as `slice`, but it allows `start` to be greater than `end`.
419413

420414
For instance:
421415

422-
423416
```js run
424417
let str = "st*!*ring*/!*ify";
425418

@@ -435,7 +428,6 @@ There are 3 methods in JavaScript to get a substring: `substring`, `substr` and
435428

436429
Negative arguments are (unlike slice) not supported, they are treated as `0`.
437430

438-
439431
`str.substr(start [, length])`
440432
: Returns the part of the string from `start`, with the given `length`.
441433

@@ -461,7 +453,6 @@ Let's recap these methods to avoid any confusion:
461453
| `substring(start, end)` | between `start` and `end` | negative values mean `0` |
462454
| `substr(start, length)` | from `start` get `length` characters | allows negative `start` |
463455

464-
465456
```smart header="Which one to choose?"
466457
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.
467458
@@ -537,7 +528,6 @@ The characters are compared by their numeric code. The greater code means that t
537528
- All lowercase letters go after uppercase letters because their codes are greater.
538529
- Some letters like `Ö` stand apart from the main alphabet. Here, it's code is greater than anything from `a` to `z`.
539530

540-
541531
### Correct comparisons
542532

543533
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 `Ṩ`
667657

668658
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.
669659

670-
671660
## Summary
672661

673662
- There are 3 types of quotes. Backticks allow a string to span multiple lines and embed expressions `${…}`.

0 commit comments

Comments
 (0)