JavaScript – Create String
To create a string in JavaScript, enclose the string literal in double quotes, single quotes, or back-ticks. Or, we can also use String() constructor.
Examples
The following are some of the quick examples to create a string in JavaScript.
var str1 = 'hello world'; var str2 = "hello world"; var str3 = `hello world`; var str4 = new String("hello world");
In the following example, we create a string in JavaScript, and display this string in a div.
index.html
ADVERTISEMENT
Conclusion
In this JavaScript Tutorial, we learned how to create a string in JavaScript, in different ways, with examples.