An escape character serves as a valuable tool that empowers you to display characters that might otherwise pose challenges due to their special interpretations by browsers. This mechanism allows you to present characters that hold distinctive meanings or formatting in a manner that aligns with your original intent, overcoming potential discrepancies in interpretation between your design and the browser's rendering.
When you run the above code, it will end in an error because the browser encounters the first double quote , it will think that the string has finished.
Using escape character
The above code will run successfully, because the browser encounters the backslash , it knows not to try to interpret the next character.
- \' single quote
- \" double quote
- \ backslash
- \n new line
- \r carriage return
- \t tab
- \b backspace
- \f form feed
- \v vertical tab (IE < 9 treats '\v' as 'v' instead of a vertical tab ('\x0B'). If cross-browser compatibility is a concern, use \x0B instead of \v.)
- \0 null character (U+0000 NULL) (only if the next character is not a decimal digit; else it’s an octal escape sequence)