These characters could be
special characters. Strings are created by enclosing
the string characters either within single quotes
' or double quotes
". Whatever you write inside these quotes will be considered as a string and will get printed as it is. You can use any digit, alphabet, or any symbol in a string.
As, a web browser ignores the whitespaces, what if we willingly wanted to have whitespace between text. How would we able to display those spaces without getting ignored by the browser ?
Escape characters helps us to display whitespace in the browser and also apart from that, provide many other helpful characters. Escape sequences using backslash
(\) are very useful for displaying those characters that can't be typed using a keyboard.
Here are some most commonly used escape sequences:
\nis used for newline character. It breaks the flow of text and then displays the text in next line.
\tis used for tab character. It displays multiple whitespaces as of length of a tab character.
\ris used for carriage-return character. It moves the cursor to the beginning of the line.
\bis used for backspace character.
\\is used for a single backslash (\)
The strings you write in the source code are written in
backticks, but browser output does not include any quotations. So, A string literal is what you write with quotation in the source code and what we see in the output is called string value.
new keyword is used to create instance of string. That instance can be used anywhere in the program as a reference to the string.
Note: If the updated content is not visible to you please refresh the cookies by pressing CTRL + Shift + R.