JavaScript Code


How to create an empty string in JavaScript?


Create an empty string

The problem statement is to create an empty string using JavaScript.

Solution

To create an empty string literal, we can use single or double quotes and not mention any value in the quotes.

str1 = '';
str1 = "";

Program

in the following HTML code, we have two paragraphs with some text. we assign the empty text (empty string) to the paragraph with id "myPara".

var str1 = "";
console.log("str1 : " + str1);