2.3 Special characters

2.3.1 Whitespace characters

Aside from the line terminator sequence, the ASCII horizontal space character(0x20) is the only whitespace character that appears anywhere in a sourcefile. This implies that

  • All other whitespace characters in string literals are escaped, and

  • Tab characters are not used for indentation.

2.3.2 Special escape sequences

For any character that has a special escape sequence (\', \", \, \b,\f, \n, \r, \t, \v), that sequence is used rather than thecorresponding numeric escape (e.g \x0a, \u000a, or \u{a}). Legacy octalescapes are never used.

2.3.3 Non-ASCII characters

For the remaining non-ASCII characters, either the actual Unicode character(e.g. ) or the equivalent hex or Unicode escape (e.g. \u221e) is used,depending only on which makes the code easier to read and understand.

Tip: In the Unicode escape case, and occasionally even when actual Unicodecharacters are used, an explanatory comment can be very helpful.

  1. /* Best: perfectly clear even without a comment. */
  2. const units = 'μs';
  3. /* Allowed: but unncessary as μ is a printable character. */
  4. const units = '\u03bcs'; // 'μs'
  5. /* Good: use escapes for non-printable characters with a comment for clarity. */
  6. return '\ufeff' + content; // Prepend a byte order mark.
  1. /* Poor: the reader has no idea what character this is. */
  2. const units = '\u03bcs';

Tip: Never make your code less readable simply out of fear that some programsmight not handle non-ASCII characters properly. If that happens, those programsare broken and they must be fixed.