JavaScript Code


How to create string using double quotes in JavaScript?


Create String using Double Quotes

to create a string literal using double quotes in JavaScript, enclose your string value in double quotes

in the following example, we have a string literal defined using double quotes

"Hello World"

if we were to use a double quote inside the string when the string is defined using double quotes, we must escape the double quote inside the string using backslash

to define a string literal with value Machine said, "Hello World!". using single quotes, we must define it as shown in the following

"Machine said, \"Hello World!\"."

Example

in the following script, we define a string using double quotes, and print it to console output

let message = "Hello World";
console.log(message);