85 JavaScript Code Assists for Visual Studio Code
Tags: vscode, javascript, typescript, beginners
Published: 2022-05-30 17:07:12

JavaScript programming in an editor such as Visual Studio Code typically involves a lot of manual text editing, with the occasional copy-paste keyboard shortcuts or multi-cursor changes.

**Code assists** such as refactorings, code actions, and quick fixes are another tool in this repertoire. You can use code assists to **make higher-level language-aware changes**, e.g., you can extract an expression and all of its occurrences into a variable. When you make such changes manually, it can be time-consuming, and you risk making mistakes.

I've written an extension for Visual Studio Code called [JavaScript Assistant](https://marketplace.visualstudio.com/items?itemName=p42ai.refactor) that adds 85 code assists for JavaScript and TypeScript to make your life easier. **You can find the code assists in refactoring and quick-fix context menus or invoke them with keyboard shortcuts**. The JavaScript Assistant will also sometimes suggest recommended refactorings.

In this blog post, you can learn about code assists and how to improve your refactoring skills. Here are the code assists by category:

* [Core Refactorings](#core-refactorings)
* [Code Assists for React](#code-assists-for-react)
* [Code Assists for Logical Expressions](#code-assists-for-logical-expressions)
* [Code Assists for Branching Statements](#code-assists-for-branching-statements)
* [Code Assists for Arrays and Loops](#code-assists-for-arrays-and-loops)
* [Code Assists for Functions and Methods](#code-assists-for-functions-and-methods)
* [Code Assists for Strings and Template Literals](#code-assists-for-strings-and-template-literals)
* [Code Assists for Variables](#code-assists-for-variables)
* [Code Assists for Syntax Conversion](#code-assists-for-syntax-conversion)
* [JavaScript Modernizations](#javascript-modernizations)
* [Lodash Modernizations](#lodash-modernizations)
* [Code Cleanups](#code-cleanups)
* [Other Code Assists](#other-code-assists)

Code assists that belong to several categories appear more than once.

## Core Refactorings
Visual Study Code already contains basic refactorings such as Rename and Extract Function. The JavaScript Assistant adds additional refactorings or extended functionality such as safety checking:
* **[Extract selected text into variable](https://p42.ai/documentation/code-assist/extract-substring-to-variable)**: Extract the selected text (including expressions from template literals) into a `const` variable.
![Extract selected text into variable](https://p42.ai/image/documentation/code-action/extract-substring-to-variable/vscode-example.gif#2)
* **[Extract variable](https://p42.ai/documentation/code-assist/extract-variable)**: Extract one or more occurrences of an expression into a `const` variable.
![Extract variable](https://p42.ai/image/documentation/code-action/extract-variable/vscode-example.gif#2)
* **[Inline return](https://p42.ai/documentation/code-assist/inline-return)**: Convert a variable assignment to a `return` statement.
* **[Inline variable](https://p42.ai/documentation/code-assist/inline-variable)**: Inline a variable value into its references.
![Inline variable](https://p42.ai/image/documentation/code-action/inline-variable/vscode-example.gif#2)

## Code Assists for React
 In React, components often contain JSX, a syntax extension for JavaScript. The JavaScript Assistant provides code assists that make working with JSX and React easier:
* **[Add {...} to JSX attribute](https://p42.ai/documentation/code-assist/add-braces-to-jsx-attribute)**: Add `{...}` to JSX attribute string literal value.
* **[Collapse JSX tag](https://p42.ai/documentation/code-assist/collapse-jsx-element)**: Convert an empty JSX tag into a self-closing tag.
* **[Expand JSX tag](https://p42.ai/documentation/code-assist/expand-self-closing-jsx-element)**: Expand a self-closing JSX tag.
* **[Extract React function component](https://p42.ai/documentation/code-assist/extract-jsx-element)**: Extract JSX element or fragment into a React Function Component.
![Extract React function component](https://p42.ai/image/documentation/code-action/extract-jsx-element/vscode-example.gif#2)
* **[Remove {...} from JSX attribute](https://p42.ai/documentation/code-assist/remove-braces-from-jsx-attribute)**: Remove `{...}` from a JSX attribute expression value that contains a string literal.
* **[Remove unnecessary JSX fragment](https://p42.ai/documentation/code-assist/remove-unnecessary-jsx-fragment)**: Replace JSX Fragments `<></>` that only contain a single child with that child.
* **[Surround with <>...</>](https://p42.ai/documentation/code-assist/surround-with-jsx-fragment)**: Wrap JSX elements in a JSX fragment `<>...</>`.

## Code Assists for Logical Expressions
Boolean logic can be challenging to read, especially as expressions get more complex. The JavaScript Assistant provides several refactorings that can help you simplify and tease apart logical expressions to make them easier to understand:
* **[Convert string comparison chain to array.includes](https://p42.ai/documentation/code-assist/convert-comparison-chain-to-array-includes)**: Replace `|| value === 'aString'` and `&& value !== 'aString'`  chains with `array.includes()`.
![Convert string comparison chain to array.includes](https://p42.ai/image/documentation/code-action/convert-comparison-chain-to-array-includes/vscode-example.gif#2)
* **[Convert to optional chaining](https://p42.ai/documentation/code-assist/convert-to-optional-chaining)**: Replace various guard expressions with the optional chaining operator (`?.`).
* **[Flip operator](https://p42.ai/documentation/code-assist/flip-operator)**: Swap the left and right operands and update the operator if necessary.
* **[Invert condition](https://p42.ai/documentation/code-assist/invert-condition)**: Negate the condition of an if-statement or conditional expression and swap its content.
![Invert condition](https://p42.ai/image/documentation/code-action/invert-condition/vscode-example.gif#2)
* **[Pull up negation](https://p42.ai/documentation/code-assist/pull-up-negation)**: Move the not-operator (`!`) out of a binary expression.
* **[Push down negation](https://p42.ai/documentation/code-assist/push-down-negation)**: Push the not-operator (`!`) into an expression and negate it.
* **[Remove double negation](https://p42.ai/documentation/code-assist/remove-double-negation)**: Remove double negation (`!!`) expressions.
* **[Simplify binary expression](https://p42.ai/documentation/code-assist/simplify-binary-expression)**: Replace binary expression with a more straightforward equivalent expression.
* **[Use == null comparison](https://p42.ai/documentation/code-assist/use-eq-eq-null)**: Replace different nullish checks with `== null`.

## Code Assists for Branching Statements
Branching statements such as if-else and switch are central elements in many programs. Restructuring them can increase the readability of your programs, often in combination with refactoring their conditions:
* **[Convert && to if statement](https://p42.ai/documentation/code-assist/convert-and-and-guard-to-if-statement)**: Convert `condition && aFunction();` and similar expression statements into if statements.
* **[Convert conditional expression to if-else](https://p42.ai/documentation/code-assist/convert-conditional-expression-to-if-else)**: Convert a conditional expression to an if-else statement.
* **[Convert if-else into conditional expression](https://p42.ai/documentation/code-assist/convert-if-else-to-conditional-expression)**: Convert an `if`-`else` return or assignment expression into a conditional expression.
* **[Convert if-else to switch](https://p42.ai/documentation/code-assist/convert-if-else-to-switch)**: Convert if-else statement chain with equality comparisons to switch statement.
![Convert if-else to switch](https://p42.ai/image/documentation/code-action/convert-if-else-to-switch/vscode-example.gif#2)
* **[Merge nested if inside else into else-if](https://p42.ai/documentation/code-assist/merge-nested-else-if)**: Nested single `if` statements inside `else` blocks can be combined into `else if` statements.
* **[Merge nested if-statements](https://p42.ai/documentation/code-assist/merge-nested-if)**: Combine two nested `if` statements without additional operations into a single `if`-statement, using `&&` to combine the conditions.
* **[Move duplicated first statement out of if-else](https://p42.ai/documentation/code-assist/move-first-statement-out-of-if-else)**: Move a first statement that appears in both the if and the else block out of the if-else statement.
![Move duplicated first statement out of if-else](https://p42.ai/image/documentation/code-action/move-first-statement-out-of-if-else/vscode-example.gif#2)
* **[Move duplicated last statement out of if-else](https://p42.ai/documentation/code-assist/move-last-statement-out-of-if-else)**: Move a last statement that appears in both the if and the else block out of the if-else statement.
* **[Remove empty else block](https://p42.ai/documentation/code-assist/remove-empty-else-block)**: Remove an empty 'else' block from an 'if' statement.
* **[Remove empty if block](https://p42.ai/documentation/code-assist/remove-empty-if-block)**: Remove an empty 'if' block from an 'if' statement. Replaces it with the 'else' block when available.
* **[Remove redundant else if](https://p42.ai/documentation/code-assist/remove-redundant-else)**: Remove redundant else-if conditions and unreachable else statements.
* **[Remove unnecessary conditional expression](https://p42.ai/documentation/code-assist/remove-unnecessary-conditional-expression)**: Replace a conditional expression with its condition or its result.
* **[Remove unnecessary else](https://p42.ai/documentation/code-assist/remove-unnecessary-else)**: Lift the else content of an `if`-`else` with a return statement to the outer indentation level.
* **[Separate repeated condition into nested if-else](https://p42.ai/documentation/code-assist/separate-condition-into-nested-if)**: Separate a repeated sub-condition that is fully covered into a nested if-else.
* **[Split if statement](https://p42.ai/documentation/code-assist/split-if)**: Split the condition of an if statement on `||` or `&&` when possible.
![Split if statement](https://p42.ai/image/documentation/code-action/split-if/vscode-example.gif#2)

## Code Assists for Arrays and Loops
JavaScript has several ways of defining loops and many array methods that work on the whole array. The JavaScript Assistant provides several code actions for converting between different types of `for` loops and for converting to more idiomatic array methods such as `array.includes()`.

* **[Convert array.indexOf() into array.includes()](https://p42.ai/documentation/code-assist/convert-array-index-of-to-array-includes)**: Replace `array.indexOf()` checks with `array.includes()`.
* **[Convert string comparison chain to array.includes](https://p42.ai/documentation/code-assist/convert-comparison-chain-to-array-includes)**: Replace `|| value === 'aString'` and `&& value !== 'aString'`  chains with `array.includes()`.
* **[Convert loop to .forEach](https://p42.ai/documentation/code-assist/convert-loop-to-for-each)**: Replace regular `for` loops with `.forEach()` loops.
* **[Convert loop to for..of](https://p42.ai/documentation/code-assist/convert-loop-to-for-of)**: Replace regular `for` loops and `anArray.forEach` loops with `for...of` loops.
![Convert loop to for..of](https://p42.ai/image/documentation/code-action/convert-loop-to-for-of/vscode-example.gif#2)
* **[Convert loop to for](https://p42.ai/documentation/code-assist/convert-loop-to-for-with-index)**: Replace `for..of` with a regular `for` loop that has an index variable.

## Code Assists for Functions and Methods
Functions and methods are essential building blocks of any non-trivial program. The following code actions make it easier to work with functions, methods, and their parameters:

* **[Add {…} to arrow function](https://p42.ai/documentation/code-assist/add-braces-to-arrow-function)**: Convert arrow function expression body into a block body.
* **[Convert function to arrow function](https://p42.ai/documentation/code-assist/convert-function-to-arrow-function)**: Replace function expressions with arrow functions, a more concise syntax.
![Convert function to arrow function](https://p42.ai/image/documentation/code-action/convert-function-to-arrow-function/vscode-example.gif#2)
* **[Convert function to object method](https://p42.ai/documentation/code-assist/convert-function-to-object-method)**: Convert property assignments with functions to method declarations.
* **[Convert named function to function expression](https://p42.ai/documentation/code-assist/convert-named-function-to-function-expression)**: Converts a named function to a const declaration with a function expression.
* **[Lift default into parameter](https://p42.ai/documentation/code-assist/lift-default-into-parameter)**: Replace default value assignment expressions with default parameter values.
![Lift default into parameter](https://p42.ai/image/documentation/code-action/lift-default-into-parameter/vscode-example.gif#2)
* **[Push parameter into IIFE/IIAF](https://p42.ai/documentation/code-assist/push-parameter-into-iife)**: Push a parameter of an immediately-invoked function expressions (IIFEs) or an immediately-invoked arrow functions (IIAFs) into the function body.
* **[Remove {…} from arrow function](https://p42.ai/documentation/code-assist/remove-braces-from-arrow-function)**: Convert an arrow function block body into an expression body.
* **[Remove IIFE/IIAF](https://p42.ai/documentation/code-assist/remove-iife)**: Remove immediately-invoked function expressions (IIFEs) and immediately-invoked arrow functions (IIAFs) without parameters.

## Code Assists for Strings and Template Literals
Text manipulation has become more powerful with the introduction of template literals in JavaScript. The JavaScript Assistant offers several code actions to help you work with text, be it strings or template literals:

* **[Convert string comparison chain to array.includes](https://p42.ai/documentation/code-assist/convert-comparison-chain-to-array-includes)**: Replace `|| value === 'aString'` and `&& value !== 'aString'`  chains with `array.includes()`.
* **[Convert string to template literal](https://p42.ai/documentation/code-assist/convert-string-to-template-literal)**: Convert a string to a basic template literal without expressions.
* **[Convert template literal to string](https://p42.ai/documentation/code-assist/convert-template-literal-to-string)**: Convert a simple template literal without expressions into a string.
* **[Extract selected text into variable](https://p42.ai/documentation/code-assist/extract-substring-to-variable)**: Extract the selected text (including expressions from template literals) into a `const` variable.
* **[Inline into template](https://p42.ai/documentation/code-assist/inline-into-template)**: Inline a string or a basic template literal into an outer template literal.
![Inline into template](https://p42.ai/image/documentation/code-action/inline-into-template/vscode-example.gif#2)
* **[Remove unnecessary template literal](https://p42.ai/documentation/code-assist/remove-unnecessary-template)**: Simplify a template literal with a single inner expression and no prefix or suffix.
* **[Use string.endsWith()](https://p42.ai/documentation/code-assist/use-string-ends-with)**: `string.endsWith()` checks if a string ends with another string.
* **[Use string.startsWith()](https://p42.ai/documentation/code-assist/use-string-starts-with)**: `string.startsWith()` checks if a string starts with another string.
* **[Merge string concatenation](https://p42.ai/documentation/code-assist/use-template-literal)**: Merge string and template literal concatenation into a single template literal or string.
![Merge string concatenation](https://p42.ai/image/documentation/code-action/use-template-literal/vscode-example.gif#2)

## Code Assists for Variables

* **[Convert let to const](https://p42.ai/documentation/code-assist/convert-let-to-const)**: Replace `let` declarations that have no re-assignment with `const` declarations.
* **[Convert to destructuring assignment](https://p42.ai/documentation/code-assist/convert-to-destructuring-assignment)**: Convert a variable declaration that accesses an object property to a destructuring assignment.
![Convert to destructuring assignment](https://p42.ai/image/documentation/code-action/convert-to-destructuring-assignment/vscode-example.gif#2)
* **[Extract variable](https://p42.ai/documentation/code-assist/extract-variable)**: Extract one or more occurrences of an expression into a `const` variable.
* **[Inline return](https://p42.ai/documentation/code-assist/inline-return)**: Convert a variable assignment to a `return` statement.
* **[Lift default into parameter](https://p42.ai/documentation/code-assist/lift-default-into-parameter)**: Replace default value assignment expressions with default parameter values.
* **[Merge into preceding destructuring assignment](https://p42.ai/documentation/code-assist/merge-into-preceding-destructuring-assignment)**: Combine an object destructuring assignment with its preceding sibling.
* **[Merge variable declaration and initialization](https://p42.ai/documentation/code-assist/merge-variable-declaration-and-initialization)**: Convert the initial assignment of a variable into its declaration initializer.
* **[Move field initialization into constructor](https://p42.ai/documentation/code-assist/move-field-initializer-into-constructor)**: Moves the assignment of the initial field value into the class constructor.
![Move field initialization into constructor](https://p42.ai/image/documentation/code-action/move-field-initializer-into-constructor/vscode-example.gif#2)
* **[Move initialization into field declaration](https://p42.ai/documentation/code-assist/move-field-initializer-into-declaration)**: Moves the assignment of the initial field value into the field declaration.
* **[Push parameter into IIFE/IIAF](https://p42.ai/documentation/code-assist/push-parameter-into-iife)**: Push a parameter of an immediately-invoked function expressions (IIFEs) or an immediately-invoked arrow functions (IIAFs) into the function body.
* **[Remove unused variable](https://p42.ai/documentation/code-assist/remove-unused-variable)**: Remove a variable that is not read or written.
* **[Convert var to let or const](https://p42.ai/documentation/code-assist/replace-var-with-let-and-const)**: Replace `var` with block-scoped variables `let` and `const`.
* **[Split variable declaration sequence](https://p42.ai/documentation/code-assist/split-variable-declaration)**: Convert declarations with multiple variables into separate declarations for each variable.
* **[Split variable declaration and initialization](https://p42.ai/documentation/code-assist/split-variable-declaration-and-initialization)**: Separate the variable initialization from its declaration.
* **[Use nullish coalescence in default expression](https://p42.ai/documentation/code-assist/use-nullish-coalescence-in-default-expression)**: Replace default value expression with nullish coalescing operator (`??`) expressions.

## Code Assists for Syntax Conversion
It is often annoying to make small syntactical changes by editing text. Often more than one position needs to be edited, and the code is broken during the edit, leading to incorrect errors and auto-completions that get in the way. You can execute the following syntax conversions with code assists:
* **[Add {…} to arrow function](https://p42.ai/documentation/code-assist/add-braces-to-arrow-function)**: Convert arrow function expression body into a block body.
* **[Add {…} to JSX attribute](https://p42.ai/documentation/code-assist/add-braces-to-jsx-attribute)**: Add `{…}` to JSX attribute string literal value.
* **[Add numeric separator](https://p42.ai/documentation/code-assist/add-numeric-separator)**: Increase the readability of long numbers and uncommon number formats by adding underscore separators.
* **[Collapse JSX tag](https://p42.ai/documentation/code-assist/collapse-jsx-element)**: Convert an empty JSX tag into a self-closing tag.
![Collapse JSX tag](https://p42.ai/image/documentation/code-action/collapse-jsx-element/vscode-example.gif#2)
* **[Collapse object property into shorthand](https://p42.ai/documentation/code-assist/collapse-property-into-shorthand)**: Shorten object properties when the property name is the same as the property value.
* **[Convert property access to dot notation](https://p42.ai/documentation/code-assist/convert-bracket-notation-property-access-to-dot-notation)**: Convert bracket notation property access `o['a']` into dot notation property access `o.a`.
* **[Convert property access to bracket notation](https://p42.ai/documentation/code-assist/convert-dot-notation-property-access-to-bracket-notation)**: Convert dot notation property access `o.a` into bracket notation property access `o['a']`.
* **[Expand JSX tag](https://p42.ai/documentation/code-assist/expand-self-closing-jsx-element)**: Expand a self-closing JSX tag.
* **[Expand shorthand property](https://p42.ai/documentation/code-assist/expand-shorthand-property)**: Expand a shorthand object property (e.g. `{ a }`) to a regular property (e.g. `{ a: a }`).
* **[Merge variable declaration and initialization](https://p42.ai/documentation/code-assist/merge-variable-declaration-and-initialization)**: Convert the initial assignment of a variable into its declaration initializer.
* **[Pull operator out of assignment](https://p42.ai/documentation/code-assist/pull-operator-out-of-assignment)**: Move an operator out of an assignment into a binary expression.
* **[Push operator into assignment](https://p42.ai/documentation/code-assist/push-operator-into-assignment)**: Move an operator from a binary expression into an assignment operator, e.g., `+=`.
![Push operator into assignment](https://p42.ai/image/documentation/code-action/push-operator-into-assignment/vscode-example.gif#2)
* **[Remove {…} from arrow function](https://p42.ai/documentation/code-assist/remove-braces-from-arrow-function)**: Convert an arrow function block body into an expression body.
* **[Remove {…} from JSX attribute](https://p42.ai/documentation/code-assist/remove-braces-from-jsx-attribute)**: Remove `{…}` from a JSX attribute expression value that contains a string literal.

## JavaScript Modernizations
The Javascript ecosystem is progressing rapidly. However, it is hard to keep codebases up-to-date with the newer JavaScript features, and codemods are not always an option due to their significant churn and potential for breakages. The JavaScript Assistant supports both codemod-like mass code refactoring and more opportunistic code modernization for the following upgrades:
* **[Add numeric separator](https://p42.ai/documentation/code-assist/add-numeric-separator)**: Increase the readability of long numbers and uncommon number formats by adding underscore separators.
* **[Collapse object property into shorthand](https://p42.ai/documentation/code-assist/collapse-property-into-shorthand)**: Shorten object properties when the property name is the same as the property value.
* **[Convert .apply() to spread syntax](https://p42.ai/documentation/code-assist/convert-apply-to-spread-syntax)**: Replace `.apply()` calls with the spread operator `...`
* **[Convert array.indexOf() into array.includes()](https://p42.ai/documentation/code-assist/convert-array-index-of-to-array-includes)**: Replace `array.indexOf()` checks with `array.includes()`.
![Convert array.indexOf() into array.includes()](https://p42.ai/image/documentation/code-action/convert-array-index-of-to-array-includes/vscode-example.gif#2)
* **[Convert string comparison chain to array.includes](https://p42.ai/documentation/code-assist/convert-comparison-chain-to-array-includes)**: Replace `|| value === 'aString'` and `&& value !== 'aString'`  chains with `array.includes()`.
* **[Convert function to arrow function](https://p42.ai/documentation/code-assist/convert-function-to-arrow-function)**: Replace function expressions with arrow functions, a more concise syntax.
* **[Convert function to object method](https://p42.ai/documentation/code-assist/convert-function-to-object-method)**: Convert property assignments with functions to method declarations.
* **[Convert loop to for..of](https://p42.ai/documentation/code-assist/convert-loop-to-for-of)**: Replace regular `for` loops and `anArray.forEach` loops with `for...of` loops.
* **[Convert Math.pow to exponentiation operator](https://p42.ai/documentation/code-assist/convert-math-pow-to-exponentiation)**: Use the exponentiation operator `**` instead of `Math.pow()`.
![Convert Math.pow to exponentiation operator](https://p42.ai/image/documentation/code-action/convert-math-pow-to-exponentiation/vscode-example.gif#2)
* **[Convert string to template literal](https://p42.ai/documentation/code-assist/convert-string-to-template-literal)**: Convert a string to a basic template literal without expressions.
* **[Convert to destructuring assignment](https://p42.ai/documentation/code-assist/convert-to-destructuring-assignment)**: Convert a variable declaration that accesses an object property to a destructuring assignment.
* **[Convert to optional chaining](https://p42.ai/documentation/code-assist/convert-to-optional-chaining)**: Replace various guard expressions with the optional chaining operator (`?.`).
* **[Lift default into parameter](https://p42.ai/documentation/code-assist/lift-default-into-parameter)**: Replace default value assignment expressions with default parameter values.
* **[Convert var to let or const](https://p42.ai/documentation/code-assist/replace-var-with-let-and-const)**: Replace `var` with block-scoped variables `let` and `const`.
![Convert var to let or const](https://p42.ai/image/documentation/code-action/replace-var-with-let-and-const/vscode-example.gif#2)
* **[Replace void 0 with undefined](https://p42.ai/documentation/code-assist/replace-void-0-with-undefined)**: Replace `void 0` and other constant `void` expressions with `undefined`.
* **[Use == null comparison](https://p42.ai/documentation/code-assist/use-eq-eq-null)**: Replace different nullish checks with `== null`.
* **[Use nullish coalescence in default expression](https://p42.ai/documentation/code-assist/use-nullish-coalescence-in-default-expression)**: Replace default value expression with nullish coalescing operator (`??`) expressions.
![Use nullish coalescence in default expression](https://p42.ai/image/documentation/code-action/use-nullish-coalescence-in-default-expression/vscode-example.gif#2)
* **[Use string.endsWith()](https://p42.ai/documentation/code-assist/use-string-ends-with)**: `string.endsWith()` checks if a string ends with another string.
* **[Use string.startsWith()](https://p42.ai/documentation/code-assist/use-string-starts-with)**: `string.startsWith()` checks if a string starts with another string.
* **[Merge string concatenation](https://p42.ai/documentation/code-assist/use-template-literal)**: Merge string and template literal concatenation into a single template literal or string.

## Lodash Modernizations
With the introduction of various collection helpers and new syntax in ES6 and more recent JavaScript versions, some [Lodash](https://lodash.com/) functions have become somewhat redundant.

* **[Replace _.every with array.every](https://p42.ai/documentation/code-assist/replace-lodash-every-with-javascript-array-every)**: Replace Lodash `_.every` with `array.every`.
* **[Replace _.filter with array.filter](https://p42.ai/documentation/code-assist/replace-lodash-filter-with-javascript-array-filter)**: Replace Lodash `_.filter` with `array.filter`.
![Replace _.filter with array.filter](https://p42.ai/image/documentation/code-action/replace-lodash-filter-with-javascript-array-filter/vscode-example.gif#2)
* **[Replace _.each and _.forEach with array.forEach](https://p42.ai/documentation/code-assist/replace-lodash-foreach)**: Replace Lodash `_.each` and `_.forEach` with `array.forEach`.
* **[Replace _.map with array.map](https://p42.ai/documentation/code-assist/replace-lodash-map-with-javascript-array-map)**: Replace Lodash `_.map` with `array.map`.
* **[Replace _.noop with arrow Function](https://p42.ai/documentation/code-assist/replace-lodash-noop-with-arrow-function)**: Replace `_.noop` with `() => undefined`.
* **[Replace _.some with array.some](https://p42.ai/documentation/code-assist/replace-lodash-some-with-javascript-array-some)**: Replace Lodash `_.some` with `array.some`.

## Code Cleanups
Code cleanups remove unnecessary code. Such code can result from code churn, e.g., by applying other refactorings, adding new features, or fixing bugs. The JavaScript Assistant shows hints and automates the cleanup for the following situations:
* **[Remove console.log](https://p42.ai/documentation/code-assist/remove-console-log)**: Remove console.log statement.
* **[Remove double negation](https://p42.ai/documentation/code-assist/remove-double-negation)**: Remove double negation (`!!`) expressions.
* **[Remove empty else block](https://p42.ai/documentation/code-assist/remove-empty-else-block)**: Remove an empty 'else' block from an 'if' statement.
* **[Remove empty if block](https://p42.ai/documentation/code-assist/remove-empty-if-block)**: Remove an empty 'if' block from an 'if' statement. Replaces it with the 'else' block when available.
* **[Remove IIFE/IIAF](https://p42.ai/documentation/code-assist/remove-iife)**: Remove immediately-invoked function expressions (IIFEs) and immediately-invoked arrow functions (IIAFs) without parameters.
* **[Remove redundant else if](https://p42.ai/documentation/code-assist/remove-redundant-else)**: Remove redundant else-if conditions and unreachable else statements.
* **[Remove unnecessary conditional expression](https://p42.ai/documentation/code-assist/remove-unnecessary-conditional-expression)**: Replace a conditional expression with its condition or its result.
* **[Remove unnecessary else](https://p42.ai/documentation/code-assist/remove-unnecessary-else)**: Lift the else content of an `if`-`else` with a return statement to the outer indentation level.
![Remove unnecessary else](https://p42.ai/image/documentation/code-action/remove-unnecessary-else/vscode-example.gif#2)
* **[Remove unnecessary expression statement](https://p42.ai/documentation/code-assist/remove-unnecessary-expression-statement)**: Remove an expression statement that has no side-effects.
* **[Remove unnecessary JSX fragment](https://p42.ai/documentation/code-assist/remove-unnecessary-jsx-fragment)**: Replace JSX Fragments `<></>` that only contain a single child with that child.
* **[Remove unnecessary template literal](https://p42.ai/documentation/code-assist/remove-unnecessary-template)**: Simplify a template literal with a single inner expression and no prefix or suffix.
* **[Remove unused variable](https://p42.ai/documentation/code-assist/remove-unused-variable)**: Remove a variable that is not read or written.
* **[Replace void 0 with undefined](https://p42.ai/documentation/code-assist/replace-void-0-with-undefined)**: Replace `void 0` and other constant `void` expressions with `undefined`.
![Replace void 0 with undefined](https://p42.ai/image/documentation/code-action/replace-void-0-with-undefined/vscode-example.gif#2)
* **[Simplify binary expression](https://p42.ai/documentation/code-assist/simplify-binary-expression)**: Replace binary expression with a more straightforward equivalent expression.

## Other Code Assists

* **[Insert console.log for variable](https://p42.ai/documentation/code-assist/insert-console-log)**: Insert a 'console.log' statement for a selected variable when possible.
* **[Surround with try…catch](https://p42.ai/documentation/code-assist/surround-with-try-catch)**: Surround a sequence of statements in a `try…catch` block.
![Surround with try…catch](https://p42.ai/image/documentation/code-action/surround-with-try-catch/vscode-example.gif#2)

## Conclusion
With the 85 code assists shown in this blog post, you can edit your JavaScript source code at a higher level than text and make quicker and safer changes to your code. 

> 💡&nbsp;&nbsp;If you want to give [JavaScript Assistant](https://marketplace.visualstudio.com/items?itemName=p42ai.refactor) a try, you can find it on the [Visual Studio Code marketplace](https://marketplace.visualstudio.com/items?itemName=p42ai.refactor).