Introduction and Lesson Goal

Hello, eager learner! Today, we unlock the power of Escape Characters and Special Characters in JavaScript. Our adventure begins with an exploration of escape characters. We then move on to their uses and learn about special characters. Finally, we'll unravel the trick to escaping special characters in strings. Ready? Let's dive right in!

Understanding Escape Characters

The escape character in JavaScript is the backslash (\). Acting as a turning point, it gives a different interpretation to the characters that follow it. Here's a classic scenario: inserting special characters, such as quotations, within a string. We cannot use double quotes inside the string as is, as JavaScript won't be able to parse it this way, but an escape character comes to the rescue:

In this instance, the escape character (\) inserts double quotes into the string. Without it, the JavaScript compiler would throw an error. Other frequently used escape sequences include \t (tab), \n (new line), and \\ (backslash).

In this example, "\n" inserts a new line, and inserts a tab, resulting in a neatly organized output. It might look scary, but feel free to ask me for help, I'm happy to clarify things if they are not clear!

Sign up
Join the 1M+ learners on CodeSignal
Be a part of our community of 1M+ users who develop and demonstrate their skills on CodeSignal