## Splitting strings

When splitting strings, the sequence of characters we split at does not appear in the result. We can get all letters by splitting at the empty string.

Read full articleJavaScriptAll snippets in this category →

Posted on August 20, 2020JavaScript has many different assignment operators that are shorthand for longer versions. `+=`

is one of the more common ones. Most other calculations also have an assignment operator.

```
// regular assignment assigns the right value to the variable on the left
a = b
// we can shorten the code if the variable is itself part of the calculation
a = a + 5 // is the same as:
a += 5
// these are some of the available shorthand assignment operators
a += b // a = a + b addition assignment
a -= b // a = a - b subtraction assignment
a *= b // a = a * b multiplication assignment
a /= b // a = a / b division assignment
a %= b // a = a % b remainder assignment
a &&= b // a = a && b logical AND assignment
a ||= b // a = a || b logical OR assignment
```

```
// regular assignment assigns the right value to the variable on the left
a = b
// we can shorten the code if the variable is itself part of the calculation
a = a + 5 // is the same as:
a += 5
// these are some of the available shorthand assignment operators
a += b // a = a + b addition assignment
a -= b // a = a - b subtraction assignment
a *= b // a = a * b multiplication assignment
a /= b // a = a / b division assignment
a %= b // a = a % b remainder assignment
a &&= b // a = a && b logical AND assignment
a ||= b // a = a || b logical OR assignment
```

```
// regular assignment assigns the right value to the variable on the left
a = b
// we can shorten the code if the variable is itself part of the calculation
a = a + 5 // is the same as:
a += 5
// these are some of the available shorthand assignment operators
a += b // a = a + b addition assignment
a -= b // a = a - b subtraction assignment
a *= b // a = a * b multiplication assignment
a /= b // a = a / b division assignment
a %= b // a = a % b remainder assignment
a &&= b // a = a && b logical AND assignment
a ||= b // a = a || b logical OR assignment
```

```
// regular assignment assigns the right value to the variable on the left
a = b
// we can shorten the code if the variable is itself part of the calculation
a = a + 5 // is the same as:
a += 5
// these are some of the available shorthand assignment operators
a += b // a = a + b addition assignment
a -= b // a = a - b subtraction assignment
a *= b // a = a * b multiplication assignment
a /= b // a = a / b division assignment
a %= b // a = a % b remainder assignment
a &&= b // a = a && b logical AND assignment
a ||= b // a = a || b logical OR assignment
```

When splitting strings, the sequence of characters we split at does not appear in the result. We can get all letters by splitting at the empty string.

Read full articleWe can create a sequence of numbers by spreading the keys of one array into another array. We can then change that range any way we like.

Read full articleWe no longer need to install dependencies to pad a string with characters to the left or right of it.

Read full articlePutting complex logic into a function increases code readability. By giving that function a descriptive name, it can explain what is happening in it.

Read full articleThis neat little trick makes values logged to the console much more readable with a minor adjustment to how we log it.

Read full articleWe can use the value returned by Math.random() to get a random element from an array.

Read full article