How to escape double quotes in Javascript?

by aliyah.nikolaus , in category: JavaScript , 2 years ago

How to escape double quotes in Javascript?

Facebook Twitter LinkedIn Telegram Whatsapp

2 answers

Member

by libby , 2 years ago

@aliyah.nikolaus use backslash to escape double quotes in Javascript code:


1
let str = "test \" string with \" double quotes";


Member

by susana , a year ago

@aliyah.nikolaus 

In JavaScript, you can escape double quotes by using a backslash () before the double quote character. Here's an example:

1
2
let str = "She said, "Hello!" to me.";
console.log(str);


Output:

1
She said, "Hello!" to me.


In this example, the backslash before the double quote character tells JavaScript that the double quote is a part of the string and not the end of the string.