sam_lm
sam_lm

Reputation: 35

Getting an error with Console.log('\x') in JavaScript

the problem occurs only when the word after the '\' begin with 'x'. I would like to know if \x is reserved word.

Upvotes: 1

Views: 267

Answers (2)

Collin Grady
Collin Grady

Reputation: 2253

Backslash is used to escape characters. If you need a literal backslash, use \\.

Upvotes: 3

Bart Friederichs
Bart Friederichs

Reputation: 33521

It is not a reserved word, it's a way to print a character by its code:

>>> console.log('\x56');
V

In fact, Firebug tells you what's wrong if you omit the number:

SyntaxError: malformed hexadecimal character escape sequence

Like in many C-style languages, backslashes denote "escape sequences". More can be found here.

Upvotes: 7

Related Questions