JavaScript String
JavaScript String
Strings are another basic data type available in JavaScript.
They consist of zero or more characters delimited by quotes, either single quotes or double quotes. However, the string must end with the same quote mark it started with. For example, 'Hello' (valid), "Hello" (valid), "Hello' (invalid).
Note: There is no rule for which type of quote to use.
In the following example, we will display the string "Hello" using document.write() method.
Example
Concatenate Two Strings
Use "+" operator to concatenate two strings.
Example
Quote a String
To Quote a string in the middle. Do any one of the following
- Use Escapse Sequence (\') to quote a string.
- Enclose a string with double quotes to single quote a string in the middle.
- Enclose a string with single quotes to double quote a string in the middle.
Example
Create a String using Object
Use new String()
function to create an object string.
Example
Reminder
Hi Developers, we almost covered 97% of JavaScript Tutorials with examples for quick and easy learning.
We are working to cover every Single Concept in JavaScript.
Please do google search for:
Join Our Channel
Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.
This channel is primarily useful for Full Stack Web Developer.