JavaScript Code


How to create string using single quotes in JavaScript?


Create String using Single Quotes

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

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

'Hello World'

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

to define a string literal with value User's World using single quotes, we must define it as shown in the following

'User\'s World'

Example

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

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