special characters in javascript code example
Example 1: javascript have special characters
var format = /[ `!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?~]/;
document.write(format.test("My@string-with(some%text)") + "<br/>");
document.write(format.test("My string with spaces") + "<br/>");
document.write(format.test("MyStringContainingNoSpecialChars"));
Example 2: escape in javascript
escape sequences in javascript
\' single quote
\" doucle quote
\\ backslash
\n newline
\r carriage return
\t tab
\b backspace
\f form feed
Example 3: add a slash to string in javascript
var str = 'USDYEN'
var newStr = str.slice(0,3) + ' / ' + str.slice(3)
console.log(newStr)