Skip to main content

Strings

@serverSerrverlesskiy

In JavaScript, any text data is strings. However, do not forget that numbers can also be written in a string. Of all the data types, you will probably use strings the most. Let's analyze all the options for creating a new line.

Single or double quotes#

quotation marks

Either โ€˜singleโ€™ or โ€œdoubleโ€ quotes are used to create strings.

let single = 'Hello World'
let double = "Hello World" // prettier-ignore

You can use both of them, the main thing is that if you start a line with a single one, although there may be doubles inside, it must also be completed with a single one. And, accordingly, with double quotes.

let double = "Don't you think so, d'Artagnan?"
let single = '"I think so, indeed!" - cried he.'

Backslash#

shielding

If the same quotes are used inside the string as outside, then they must be escaped with a backslash - the so-called "escape character". It is appended โž• before the enclosing quotation mark `\ '' so that it does not indicate the end of the line.

Live Editor
Result
SyntaxError: Unexpected token (1:8)
1 : return ()
            ^

Note that the backslash \ is only used to correctly read the string by the interpreter, but it is not written ๐Ÿ–Š๏ธ to the string after it has been read. When a string is saved to main memory, the \ character is not added to it. You can clearly see this in the findings.

Payment#

Now you are on a stripped-down version of the site, after subscribing to Patreon, you will get full access to the training course, as well as access to our server's private channels in Discord.

Download our mobile application or get tested in our JavaScript telegram bot, and also subscribe to our news.

Become a Patron!

Sumerian school

Contributors โœจ#

Thanks goes to these wonderful people (emoji key):


Alena Yanbukhtina

๐Ÿ“–

Dmitriy Vasilev

๐Ÿ’ต

Resoner2005

๐Ÿ› ๐ŸŽจ ๐Ÿ–‹

Become a Patron!