How to escape the apostrophe in javascript?

by herminia_bruen , in category: Javascript , a year ago

How to escape the apostrophe in javascript?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by darion , a year ago

@herminia_bruen 

To escape an apostrophe in JavaScript, you can use a backslash () before the apostrophe character. This is called escaping the character.


Here's an example:

1
2
var escapedString = 'I can't believe it!';
console.log(escapedString); // Output: I can't believe it!


In the above code, the backslash () before the apostrophe in the I can't believe it! string is used to escape the character to prevent it from being interpreted as the end of the string.