JavaScript-CheatSheet-en

Modern JavaScript Syntax and Practices CheatSheet

Variable & Expression

Basic Data Type

Regex

  • Symbols
Term Description
. (period) Matches any single character, except for line breaks.
* Matches the preceding expression 0 or more times.
+ Matches the preceding expression 1 or more times.
? Preceding expression is optional (Matches 0 or 1 times).
^ Matches the beginning of the string.
$ Matches the end of the string.
  • Character groups
Term Description
\d Matches any single digit character.
\w Matches any word character (alphanumeric & underscore).
[XYZ] Character Set: Matches any single character from the character within the brackets. You can also do a range such as [A-Z]
[XYZ]+ Matches one or more of any of the characters in the set.
[^a-z] Inside a character set, the ^ is used for negation. In this example, match anything that is NOT an uppercase letter.
  • Flags: There are five optional flags. They can be used separately or together and are placed after the closing slash. Example: /[A-Z]/g I’ll only be introducing 2 here.
Term Description
g Global search
i case insensitive search
  • Advanced
Term Description
(x) Capturing Parenthesis: Matches x and remembers it so we can use it later.
(?:x) Non-capturing Parenthesis: Matches x and does not remembers it.
x(?=y) Lookahead: Matches x only if it is followed by y.

Collection

Array

Transform

The reduce() method is used to apply a function to each element in the array to reduce the array to a single value.

Function

上一页
下一页