document.addEventListener('keydown', function(event){
if(event.key === "Escape"){
//do something
}
});
JS Escape Characters
' — Single quote
" — Double quote
— Backslash
— Backspace
f — Form feed
— New line
— Carriage return
— Horizontal tabulator
WebsiteSetup.org - Beginner’s Javascript Cheat Sheet 7
v — Vertical tabulator
const name = 'My name is 'Peter'.';
console.log(name);
//Here are other ways that you can use :
Code Output
" include double quote
include backslash
new line
carriage return
v vertical tab
horizontal tab
backspace
f form feed
// What are escape characters in javascript
Escape characters (Backslash) is used when working with special characters like single quotes, double quotes, apostrophes, and ampersands. Place backslash before the characters to make it display.
console.log("This is + plus character") // This is + plus character
console.log("Welcome to "my website"!");