Push operator into assignment
Move an operator from a binary expression into an assignment operator, e.g., +=
.

Why is this refactoring helpful?
Moving an operator into the assignment is a more concise notation that emphasizes that a variable is modified with an update relative to its current value.
What do I need to consider?
Logical Assignment Operators (&&=
, ||=
and ??=
) are an ES2021 feature. They are supported on all modern browsers and on Node 15+, and but for older browsers and Node versions transpilation might be required
(compatibility).
Configuration
- Code Assist ID (for the configuration file):
push-operator-into-assignment
- You can configure custom keyboard shortcuts with this code action kind:
refactor.p42.push-operator-into-assignment
- This code assist provides refactoring suggestions. Learn how to configure the refactoring suggestion visibility.
Related Code Assists
Learn More
- Short-Circuiting in JavaScript (P42 Blog)
- Browser & Engine Support (Compatibility Table)
- P42 Code Assists