W3Newbie
  • HTML Tutorial
  • CSS Tutorial
  • Web Dev
    • VS Code Tutorial
    • Command Line Tutorial
    • Git Tutorial
    • Github Tutorial
    • Sass Tutorial
  • Courses
  • Resources
  • Tutorials
  • Click to open the search input field Click to open the search input field Search
  • Menu Menu

JavaScript Escape Sequences

Home » JavaScript Tutorial » JavaScript Introduction » JavaScript Escape Sequences

In JavaScript, escape sequences are combinations of a backslash (\) followed by one or more characters, used inside string literals to represent special characters that can’t be typed directly or would otherwise break the string’s syntax. Mastering these sequences gives you precise control over how text is displayed and formatted.

Common Escape Sequences

Escape sequences fall into two main categories: sequences for special characters (like quotes and backslashes) and sequences for formatting (like newlines and tabs).

Quotes, Backslashes, and Formatting

These are essential for using the quote character that defines the string or for including a literal backslash.

SequenceEscape DescriptionExampleOutput in the Console
\’Single Quote Escapeconst a = 'It\'s a beautiful day.';It’s a beautiful day.
\”Double Quote Escapconst b = "He said, \"Hello!\"";He said, “Hello!”
\Backslash Escapeconst c = "C:\\Users\\Data";C:\Users\Data
\nNew Lineconsole.log("Line 1\nLine 2");Line 1 (on one line)
Line 2 (on the next line)
\tTabconsole.log("Name:\tAlex");Name: Alex (includes a tab space)

Hexadecimal and Unicode Characters

Hexadecimal and unicode character sequences allow you to represent any character, including emojis, special symbols, and characters from international alphabets, using their numerical code points. Similar to using Hexidecimal “x\…” and Unicode characters “\u…” in HTML, they can be used to add characters in JavaScript.

const helloText = '\x48\x45\x4C\x4C\x4F'; 
console.log(helloText); 
// Output: HELLO

const euroSymbol = '\u20AC'; 
console.log(`The currency is: ${euroSymbol}`); 
// Output: The currency is: €

const emoji = '\u{1F389}'; // Confetti Popper emoji
console.log(`Let's celebrate! ${emoji}`); 
// Output: Let's celebrate! 🎉
JavaScript

To see more unicode characters to add to your JavaScript, see https://www.rapidtables.com/code/text/unicode-characters.html.

< Previous
Next Lesson >

  • JavaScript Tutorial
  • JavaScript Introduction
    • JavaScript’s History
    • Getting Started with JavaScript
    • JavaScript’s Syntax & Structure
    • JavaScript Variables
    • JavaScript Data Types
    • JavaScript Escape Sequences
    • JavaScript Operators
    • JavaScript Type Coercion
    • JavaScript Expressions & Statements
  • JavaScript Built-in Objects & Methods
    • JavaScript Primitives & Methods
    • JavaScript String Properties & Methods
    • JavaScript Number Methods & Global Functions
    • JavaScript Math Object
    • JavaScript Date Object
  • JavaScript Control Flow and Collections
    • JavaScript Conditional Logic
    • JavaScript Try/Catch Synchronous Error Handling
    • JavaScript Arrays
    • JavaScript Array Methods
    • JavaScript Loops
    • JavaScript Objects
    • JavaScript Objects vs. JSON
    • JavaScript Primitive vs. Reference Values

The Newbie Template Bundle

The 12 Website Bundle Pack

Subscribe on YouTube

Web Development Courses

The HTML Email Mastery Course - Build Responsive HTML Email Templates.

Latest Tutorial Posts

  • The HTML Email Mastery Course - Build Responsive HTML Email Templates.w3newbie.com
    HTML Email Mastery Course CouponOctober 12, 2020 - 8:10 pm
  • Create A 5 Page Website With PHP Includes, HTML5, CSS3 & Bootstrap 4w3newbie.com
    Create A 5 Page Website With PHP Includes, HTML5, CSS3 & Bootstrap 4April 22, 2019 - 1:48 pm
© w3newbie.com, 2026. Terms of Use. Privacy Policy.
Scroll to top Scroll to top Scroll to top