![]() This is simply a way to spread a string over multiple lines (for easier code editing, for example), without the string actually including any new line characters. The new line doesn’t become part of the string. The \ followed by a new line is not a character escape sequence, but a LineContinuation. There’s only one exception to this rule: 'abc\ Note that the escape character \ makes special characters literal. \": double quote (U+0022 QUOTATION MARK)Īll single character escapes can easily be memorized using the following regular expression: \\.\0: null character (U+0000 NULL) (only if the next character is not a decimal digit else it’s an octal escape sequence).\v: vertical tab (U+000B LINE TABULATION).\t: horizontal tab (U+0009 CHARACTER TABULATION).\r: carriage return (U+000D CARRIAGE RETURN).There are some reserved single character escape sequences for use in strings: Now that’s out of the way, let’s take a look at the different types of character escape sequences in JavaScript strings. Basically, JavaScript uses code units rather than code points. To get the actual character code of these higher code point characters in JavaScript, you’ll have to do some extra work. Since JavaScript uses UCS-2 encoding internally, higher code points are represented by a pair of (lower valued) “surrogate” pseudo-characters which are used to comprise the real character. the character with code point 0xFFFF, which is 65535 in decimal). In JavaScript, String#charCodeAt() can be used to get the numeric Unicode code point of any character up to U+FFFF (i.e. ![]() Character codes, code points, and code unitsĪ code point (also known as “character code”) is a numerical representation of a specific Unicode character.įor example, the character code of the copyright symbol © is 169, which can be written as 0xA9 in hex. Having recently written about character references in HTML and escape sequences in CSS, I figured it would be interesting to look into JavaScript character escapes as well.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |