JavaScript – Create Empty String
To create an empty string in JavaScript, do not provide any value in double quotes, single quotes, or back-ticks. Or, we can also use String() constructor and pass no parameter in the constructor call.
Examples
The following are some of the quick examples to create an empty string in JavaScript.
</>
Copy
var str1 = '';
var str2 = "";
var str3 = ``;
var str4 = new String();
In the following program, we create an empty string in JavaScript, and display this string in a div.
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
</head>
<body>
<div id="output" style="padding: 10px;background: yellow;"></div>
<script>
var str = '';
document.getElementById('output').innerHTML = str;
</script>
</body>
</html>
Conclusion
In this JavaScript Tutorial, we learned how to create an empty string in JavaScript, in different ways, with examples.