JavaScript Strings
Let’s talk about Strings, Well, to be able to exist inside the computers, string have to be modeled as series of bits and JavaScript does this using the Unicode standard. This standard assigns a number for every character for almost every language, even emojis, for instance we can said that every string can be described by a sequence of numbers.
But JavaScript use 16bits for strings elements and the Unicode standard defines more characters than the available for JavaScript and because of this some characters are defined with 2 elements.
We can define strings using single quotes, double quotes and backticks, for example:
"Hello world"
'Hello world'
`Hello world`
To add especial characters as newline, tab and even double quotes inside of an string we use the special character backslash (\), this means wherever a backslash is founded inside the string, it indicates than the character after it has a special meaning, for example:
"\tFirst line \nSecond \"line\""
//output
First line
Second "line"
For other hand, strings can’t be divided, multiplied, or subtracted, but the + operator can be used to concatenates Strings, for example:
"con"+"cat"+"e"+"nate"
//output
concatenate
Also Backtick-quoted strings, usually called template literals enable us to do a litter more, we can inject others type of values and compute operations. But we have to write the code inside this element ${code here},for example:
`half of 1000 is ${1000 / 2}`
//output
half of 1000 is 500
We can do a lot with string, there is some methods to perform others operations, but from now let’s finish here.
You can checkout more information about strings here: https://eloquentjavascript.net/