JavaScript String
15 - Oct - 2021
XpertPhp
26
The string is a combination of characters. The string is enclosed in single or double quotation marks.
The Strings are created in two ways.
- string literal
- string object
string literal
The string literal is created using single or double quotation marks.
Syntax
var <string-name>="string value";
Example
var str = "Hello World"; console.log(str);
string object
The string object is created with a new keyword. so you can see the following syntax or example for creating a string object using the new keyword.
Syntax
var <object-name>=new String("string literal");
Example
var str = new String("Hello World!"); console.log(stringname);