Character strings
Strings are widely used in programming languages. They are used to represent text entered by a user or text that will be displayed to a user.
Creating a character string
A character string is represented by an object of class String
. But since character strings are widely used in JavaScript, the language allows them to be used by surrounding them with double quotes " and "
or single quotes ' and '
. It is also possible, for certain uses, to use backticks (reverse quotation marks ' and ')
.
Note
The string literal must in this case begin and end with the same type of quotes.
Now let’s see how to create a string using these various methods.
Creating a string literal using double or single quotes
The easiest way to create a string literal is to use the single or double quote notation:
Creating a string literal with double quotes
var s = "String 1"; console.log("s =", s);
Or, with single...