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.

Related Threads:

How to escape quotes in PHP?
How to escape a semicolon in presto?
How to escape special characters in oracle?
How to escape brackets in sparql string?
How to escape `--' in git submodule name?
How to escape a single quote in presto?