JavaScript Strings
A string (or a text string) is a series of characters like “John Doe”.
Strings are written with quotes. You can use single or double quotes:
Example :
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Strings</h2>
<p>Strings are written with quotes. You can use single or double quotes:</p>
<p id=”demo”></p>
<script>
let carName1 = “Volvo XC60”;
let carName2 = ‘Volvo XC60’;
document.getElementById(“demo”).innerHTML =
carName1 + “<br>” +
carName2;
</script>
</body>
</html>
Output
JavaScript Strings
Strings are written with quotes. You can use single or double quotes:
Volvo XC60
Volvo XC60
Description :
In JavaScript, a string is a sequence of characters used to represent text. Strings are one of the most commonly used data types and can contain letters, numbers, symbols, or even spaces. Java Script methods and properties are also available to strings, because JavaScript treats strings as objects when executing methods and properties.
Strings are written inside quotes, and JavaScript allows the use of single ('
), double ("
), or backtick (`
) quotes: