<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: P42</title>
    <description>The latest articles on DEV Community by P42 (@p42).</description>
    <link>https://dev.to/p42</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Forganization%2Fprofile_image%2F3811%2Ffa89e177-1db8-4230-be2a-3c051b652032.png</url>
      <title>DEV Community: P42</title>
      <link>https://dev.to/p42</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/p42"/>
    <language>en</language>
    <item>
      <title>AI-generated explanations and documentation for JavaScript code</title>
      <dc:creator>Lars Grammel</dc:creator>
      <pubDate>Thu, 08 Dec 2022 15:17:39 +0000</pubDate>
      <link>https://dev.to/p42/ai-generated-explanations-and-comments-for-javascript-code-1i96</link>
      <guid>https://dev.to/p42/ai-generated-explanations-and-comments-for-javascript-code-1i96</guid>
      <description>&lt;p&gt;As a JavaScript developer, you know how challenging it can be to work with existing codebases. Often, the code is poorly documented, making it difficult to understand what it does and how it works. That's why I've added two new AI-powered features to the &lt;a href="https://p42.ai?utm_medium=article&amp;amp;utm_source=devto" rel="noopener noreferrer"&gt;JS Assistant&lt;/a&gt; for Visual Studio Code: AI-generated JS-Doc comments and AI-generated explanations for code snippets.&lt;/p&gt;

&lt;h3&gt;
  
  
  AI-generated JSDoc comments
&lt;/h3&gt;

&lt;p&gt;The JS Assistant can &lt;a href="https://p42.ai/documentation/code-assist/document-function?utm_medium=article&amp;amp;utm_source=devto" rel="noopener noreferrer"&gt;generate documentation for functions and methods&lt;/a&gt;. This feature accelerates writing JSDoc comments by providing a pre-filled template you can refine.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6f80s6bjnl32ue2c2hwj.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6f80s6bjnl32ue2c2hwj.gif" alt="JS Assistant generates JSDoc comment" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  AI-generated code explanations
&lt;/h3&gt;

&lt;p&gt;You can &lt;a href="https://p42.ai/documentation/code-assist/explain-code?utm_medium=article&amp;amp;utm_source=devto" rel="noopener noreferrer"&gt;generate explanations of JavaScript code snippets&lt;/a&gt; to help you understand complex or challenging code passages. While such AI-generated descriptions can sometimes be inaccurate or misleading, they can help accelerate making sense of a legacy codebase. They are best used with your code understanding, e.g., to provide ideas that get you started or unstuck.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvabwpkunnu4ftz8ah1bh.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvabwpkunnu4ftz8ah1bh.gif" alt="JS Assistant generates code explanation" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;These AI-powered actions can help you work more effectively in complex legacy JavaScript code today. &lt;/p&gt;

&lt;p&gt;Code explanations and comment generation are early, experimental features. I would love to hear how you think they would be helpful?&lt;/p&gt;

</description>
      <category>watercooler</category>
    </item>
    <item>
      <title>6 VS Code Extensions for Productive Javascript and TypeScript Editing</title>
      <dc:creator>Lars Grammel</dc:creator>
      <pubDate>Tue, 01 Nov 2022 17:20:54 +0000</pubDate>
      <link>https://dev.to/p42/6-vs-code-extensions-for-productive-javascript-and-typescript-editing-35l3</link>
      <guid>https://dev.to/p42/6-vs-code-extensions-for-productive-javascript-and-typescript-editing-35l3</guid>
      <description>&lt;p&gt;&lt;strong&gt;Code editing is an essential part of the development workflow&lt;/strong&gt;. It includes all your actions in the editor before re-running your tests or checking how your changes affect the app you are working on:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Adding, changing, and removing code&lt;/li&gt;
&lt;li&gt;Fixing syntax errors&lt;/li&gt;
&lt;li&gt;Fixing typos, e.g., in variable and function names&lt;/li&gt;
&lt;li&gt;Fixing linter errors and warnings&lt;/li&gt;
&lt;li&gt;Formatting&lt;/li&gt;
&lt;li&gt;Refactoring and restructuring code&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Having minor friction points in the code editing process can lead to wasted time and frustration&lt;/strong&gt;. You might have to switch context and lose your train of thought when, for example, you don't immediately see or understand a syntax error, you miss a potential bug, or your editor is suddenly full of formatting-related linter warnings.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://code.visualstudio.com/" rel="noopener noreferrer"&gt;Visual Studio Code&lt;/a&gt; provides a solid editing experience and offers many extensions you can install to take it to the next level. These six Visual Studio Code extensions (&lt;a href="https://marketplace.visualstudio.com/items?itemName=p42ai.vscode-javascript-editing-extension-pack" rel="noopener noreferrer"&gt;extension pack&lt;/a&gt;) help me &lt;strong&gt;stay in the flow and be productive when editing JavaScript and TypeScript code&lt;/strong&gt;:&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;a href="https://marketplace.visualstudio.com/items?itemName=GitHub.copilot&amp;amp;ssr=false" rel="noopener noreferrer"&gt;GitHub Copilot&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://marketplace.visualstudio.com/items?itemName=GitHub.copilot&amp;amp;ssr=false" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fp42.ai%2Fimage%2Fblog%2F2022-11-01-6-vs-code-extensions-for-productive-javascript-and-typescript-editing%2Fcopilot.png" alt="GitHub Copilot Example"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href="https://marketplace.visualstudio.com/items?itemName=GitHub.copilot" rel="noopener noreferrer"&gt;GitHub Copilot&lt;/a&gt;&lt;/strong&gt; suggests code completions for your current editor position. Its AI-generated suggestions range from short statement completion to full functions and classes.&lt;/p&gt;

&lt;p&gt;Copilot is, for example, valuable for automatically &lt;strong&gt;generating boilerplate code&lt;/strong&gt;, &lt;strong&gt;discovering APIs&lt;/strong&gt;, and &lt;strong&gt;implementing common patterns&lt;/strong&gt; quickly. It is also helpful for &lt;strong&gt;getting unstuck&lt;/strong&gt; when it is not immediately clear what code is needed to solve a problem.&lt;/p&gt;

&lt;p&gt;The code suggestions are only sometimes perfect and need review and refinement, and often I discard them entirely. Still, overall, Copilot boosts my productivity and helps me stay in the flow.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;a href="https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode&amp;amp;ssr=false" rel="noopener noreferrer"&gt;Prettier&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode&amp;amp;ssr=false" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fp42.ai%2Fimage%2Fblog%2F2022-11-01-6-vs-code-extensions-for-productive-javascript-and-typescript-editing%2Fprettier.png" alt="Prettier Logo"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Consistent formatting makes code easier to read and reduces accidental churn in pull requests. However, manually formatting your code is very tedious and error-prone. You can save time and keep your codebase consistently styled with an automated code formatter.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href="https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode&amp;amp;ssr=false" rel="noopener noreferrer"&gt;Prettier&lt;/a&gt;&lt;/strong&gt; is an opinionated code formatter that many JavaScript and TypeScript projects use. It can format JavaScript, TypeScript, JSON, HTML, JSX (React), CSS, and more. Because it only offers a handful of configuration options, using Prettier can help avoid bike-shedding discussions about code formatting.&lt;/p&gt;

&lt;p&gt;You can configure Prettier to &lt;strong&gt;format your code automatically when you save a file&lt;/strong&gt;. If you want to minimize modifications to existing files, you can limit the formatting to the modified code. These are the Visual Studio Code settings for configuring Prettier:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="w"&gt;

&lt;/span&gt;&lt;span class="nl"&gt;"editor.defaultFormatter"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"esbenp.prettier-vscode"&lt;/span&gt;&lt;span class="err"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="nl"&gt;"editor.formatOnSave"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="err"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="nl"&gt;"editor.formatOnSaveMode"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"modificationsIfAvailable"&lt;/span&gt;&lt;span class="w"&gt;


&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;If you use a keyboard shortcut to save often, e.g., after each small code change, fix, or refactoring, you can even write poorly formatted code and rely on Prettier to fix it without much friction.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;a href="https://marketplace.visualstudio.com/items?itemName=quick-lint.quick-lint-js&amp;amp;ssr=false" rel="noopener noreferrer"&gt;quick-lint-js&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://marketplace.visualstudio.com/items?itemName=quick-lint.quick-lint-js&amp;amp;ssr=false" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fp42.ai%2Fimage%2Fblog%2F2022-11-01-6-vs-code-extensions-for-productive-javascript-and-typescript-editing%2Fquick-lint-js.png" alt="quick-lint-js example"&gt;&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;&lt;a href="https://marketplace.visualstudio.com/items?itemName=quick-lint.quick-lint-js&amp;amp;ssr=false" rel="noopener noreferrer"&gt;quick-lint-js&lt;/a&gt;&lt;/strong&gt; is an excellent alternative to &lt;a href="https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint&amp;amp;ssr=false" rel="noopener noreferrer"&gt;ESLint&lt;/a&gt; when you primarily want to check for code correctness. It provides a fixed set of rules for TypeScript and JavaScript and is extremely fast. &lt;/p&gt;

&lt;p&gt;While quick-lint-js does not have the extensibility and the configuration options of ESLint, it helps you &lt;strong&gt;see common mistakes quickly and fix them&lt;/strong&gt;. And since it focuses on correctness, quick-lint-js does not contain opinionated style rules and works very well with Prettier.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;a href="https://marketplace.visualstudio.com/items?itemName=streetsidesoftware.code-spell-checker&amp;amp;ssr=false" rel="noopener noreferrer"&gt;Code Spell Checker&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://marketplace.visualstudio.com/items?itemName=streetsidesoftware.code-spell-checker&amp;amp;ssr=false" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fp42.ai%2Fimage%2Fblog%2F2022-11-01-6-vs-code-extensions-for-productive-javascript-and-typescript-editing%2Fcode-spell-checker.png" alt="Code Spell Checker example"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Not all mistakes result in syntax errors or potential bugs. It is easy to have a typo in a variable, function, or class name without noticing it. However, this can lead to future issues with searchability and readability. &lt;strong&gt;&lt;a href="https://marketplace.visualstudio.com/items?itemName=streetsidesoftware.code-spell-checker&amp;amp;ssr=false" rel="noopener noreferrer"&gt;Code Spell Checker&lt;/a&gt; helps you spot and correct typos&lt;/strong&gt; early.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;a href="https://marketplace.visualstudio.com/items?itemName=p42ai.refactor&amp;amp;ssr=false" rel="noopener noreferrer"&gt;P42 JS Assistant&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://marketplace.visualstudio.com/items?itemName=p42ai.refactor&amp;amp;ssr=false" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fp42.ai%2Fimage%2Fblog%2F2022-11-01-6-vs-code-extensions-for-productive-javascript-and-typescript-editing%2Fp42-js-assistant.png" alt="P42 JS Assistant example"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Small refactorings can help restructure and clean up your code while editing it. I have developed the &lt;strong&gt;&lt;a href="https://marketplace.visualstudio.com/items?itemName=p42ai.refactor&amp;amp;ssr=false" rel="noopener noreferrer"&gt;P42 JS Assistant&lt;/a&gt;&lt;/strong&gt;, which provides many &lt;strong&gt;automated code actions&lt;/strong&gt; and &lt;strong&gt;suggests refactorings&lt;/strong&gt; that make your code more readable and modern.&lt;/p&gt;

&lt;p&gt;You can open a context menu with code actions in the editor by clicking on the lightbulb icon or using the quick-fix keyboard shortcut (Ctrl + . on Windows and Linux and ⌘ + . on Mac). You can use the code actions to make semantic changes to your code quickly and safely.&lt;/p&gt;

&lt;p&gt;The refactoring suggestions show places where you can simplify or modernize your code. They can help you stay up-to-date with the latest JavaScript idioms and best practices. An underline with three dots indicates that a refactoring suggestion is available.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;a href="https://marketplace.visualstudio.com/items?itemName=usernamehw.errorlens&amp;amp;ssr=false" rel="noopener noreferrer"&gt;Error Lens&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://marketplace.visualstudio.com/items?itemName=usernamehw.errorlens&amp;amp;ssr=false" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fp42.ai%2Fimage%2Fblog%2F2022-11-01-6-vs-code-extensions-for-productive-javascript-and-typescript-editing%2Ferror-lens.png" alt="Error Lens example"&gt;&lt;/a&gt;&lt;br&gt;
By default, the VS Code editor indicates the presence of errors, warnings, and other hints with various underlines. You need to hover over the underlined code section with the mouse cursor to be able to read the messages. This additional step can take time and requires you to use the mouse.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href="https://marketplace.visualstudio.com/items?itemName=usernamehw.errorlens&amp;amp;ssr=false" rel="noopener noreferrer"&gt;Error Lens&lt;/a&gt; shows the diagnostic messages on the same line in the editor&lt;/strong&gt;, saving you time and keeping you in the flow. You can distinguish different message levels using their color. Errors are displayed in red, warnings in yellow, information messages in blue, and hints in green. &lt;/p&gt;

&lt;p&gt;In addition to showing TypeScript and JavaScript errors, the message coloring makes Error Lens an excellent companion to quick-lint-js (error, warnings), Code Spell Checker (information), and the P42 JS Assistant (hint). You can toggle the display of different message types with the &lt;code&gt;Error Lens: Toggle&lt;/code&gt; commands in the Command Palette.&lt;/p&gt;

&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;p&gt;Editing code is central to software development. With the above Visual Studio Code extensions, you can enhance your editing experience and make it easier to write high-quality code. You can conveniently install the extensions using the &lt;strong&gt;&lt;a href="https://marketplace.visualstudio.com/items?itemName=p42ai.vscode-javascript-editing-extension-pack&amp;amp;ssr=false" rel="noopener noreferrer"&gt;JavaScript and TypeScript Editing extension pack&lt;/a&gt;&lt;/strong&gt;.&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>javascript</category>
      <category>webdev</category>
      <category>vscode</category>
    </item>
    <item>
      <title>How to Configure the Touch Bar in Visual Studio Code in Under 5 Minutes</title>
      <dc:creator>Lars Grammel</dc:creator>
      <pubDate>Thu, 20 Oct 2022 18:34:47 +0000</pubDate>
      <link>https://dev.to/p42/how-to-configure-the-touch-bar-in-visual-studio-code-in-under-5-minutes-50lm</link>
      <guid>https://dev.to/p42/how-to-configure-the-touch-bar-in-visual-studio-code-in-under-5-minutes-50lm</guid>
      <description>&lt;p&gt;The touch bar on the MacBook has the potential to provide &lt;strong&gt;quick access to commonly used commands&lt;/strong&gt; in Visual Studio Code.&lt;/p&gt;

&lt;p&gt;In the default configuration, the 'go forward' and 'go back' buttons are very useful. However, other default touch bar actions are less valuable and take up space. You might also find that everyday operations such as 'rename' (&lt;code&gt;F2&lt;/code&gt;) or 'go to definition' (&lt;code&gt;F12&lt;/code&gt;) are harder to access because you need to hold down &lt;code&gt;Fn&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;This post will show you how to &lt;strong&gt;configure Visual Studio Code to make the most of the touch bar&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Nasc Touchbar extension
&lt;/h2&gt;

&lt;p&gt;The &lt;strong&gt;&lt;a href="https://marketplace.visualstudio.com/items?itemName=felipe.nasc-touchbar&amp;amp;ssr=false" rel="noopener noreferrer"&gt;Nasc Touchbar extension&lt;/a&gt;&lt;/strong&gt; enables you to easily add many additional actions to the touch bar, for example, &lt;code&gt;Run command&lt;/code&gt;, &lt;code&gt;Toggle side bar&lt;/code&gt;, and &lt;code&gt;Rename&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;You can configure which buttons are displayed in the Visual Studio Code settings (&lt;code&gt;Preferences &amp;gt; Open Settings (UI)&lt;/code&gt;, search for &lt;code&gt;touch&lt;/code&gt;).&lt;/p&gt;

&lt;h2&gt;
  
  
  JavaScript Assistant extension
&lt;/h2&gt;

&lt;p&gt;I have included touch bar buttons that are helpful for JavaScript and TypeScript users in the &lt;a href="https://marketplace.visualstudio.com/items?itemName=p42ai.refactor&amp;amp;ssr=false" rel="noopener noreferrer"&gt;JavaScript Assistant extension&lt;/a&gt;. The extension adds the following actions to the touch bar:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;✏️ Rename: Triggers the rename command on the current symbol.&lt;/li&gt;
&lt;li&gt;🪄 Quick-Fix: Opens the quick-fix context menu.&lt;/li&gt;
&lt;li&gt;🔧 Refactor: Opens the refactor context menu.&lt;/li&gt;
&lt;li&gt;📄 Source Action: Opens the source action context menu.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The actions are only available when you edit JavaScript or TypeScript files. Similar to the Nasc Touchbar extension, you can configure which buttons are displayed in the Visual Studio Code settings (&lt;code&gt;Preferences &amp;gt; Open Settings (UI)&lt;/code&gt;).&lt;/p&gt;

&lt;h2&gt;
  
  
  Disabling default debug touch bar actions
&lt;/h2&gt;

&lt;p&gt;The default touch bar buttons take precedence over the controls added by the Nasc Touchbar and JavaScript Assistant extensions. In particular, the debug actions can take up a lot of space and hide other buttons.&lt;br&gt;
You can disable them by adding the following to your &lt;code&gt;settings.json&lt;/code&gt; file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="nl"&gt;"keyboard.touchbar.ignored"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="s2"&gt;"workbench.action.debug.start"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="s2"&gt;"workbench.action.debug.run"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="s2"&gt;"workbench.action.debug.pause"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="s2"&gt;"workbench.action.debug.stepOut"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="s2"&gt;"workbench.action.debug.stepInto"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="s2"&gt;"workbench.action.debug.stepOver"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="s2"&gt;"workbench.action.debug.stop"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="s2"&gt;"workbench.action.debug.restart"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Example configuration
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgog7i4qi6cz1a6dff7a0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgog7i4qi6cz1a6dff7a0.png" alt="Visual Studio Code Touch Bar"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The above configuration shows the following buttons:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;Go back&lt;/code&gt; and &lt;code&gt;Go forward&lt;/code&gt; (default)&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Go to definition&lt;/code&gt;, &lt;code&gt;Run command&lt;/code&gt;, &lt;code&gt;Toggle side bar&lt;/code&gt;, and &lt;code&gt;Toggle bottom panel&lt;/code&gt; (Nasc Touchbar)&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Rename&lt;/code&gt;, &lt;code&gt;Source Action&lt;/code&gt;, &lt;code&gt;Refactor&lt;/code&gt;, and &lt;code&gt;Quick-Fix&lt;/code&gt; (JavaScript Assistant)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In addition to the disable configuration for the debug actions, the following settings are used:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="nl"&gt;"nasc-touchbar.addCursorBelow"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="err"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="nl"&gt;"nasc-touchbar.rename"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="err"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="nl"&gt;"nasc-touchbar.toggleSidebar"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>vscode</category>
      <category>javascript</category>
      <category>productivity</category>
    </item>
    <item>
      <title>How would you refactor this code? (tennis-3-modern)</title>
      <dc:creator>Lars Grammel</dc:creator>
      <pubDate>Thu, 18 Aug 2022 09:13:54 +0000</pubDate>
      <link>https://dev.to/p42/how-would-you-refactor-this-code-tennis-3-modern-40h7</link>
      <guid>https://dev.to/p42/how-would-you-refactor-this-code-tennis-3-modern-40h7</guid>
      <description>&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nx"&gt;TennisGame&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;p1N&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;p2N&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;p2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;p1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;p1N&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;p1N&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;p2N&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;p2N&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nx"&gt;getScore&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;s&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;p1&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;p2&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;p1&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;p2&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;p&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Love&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Fifteen&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Thirty&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Forty&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
      &lt;span class="nx"&gt;s&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;p&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;p1&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;p1&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;p2&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;s&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;-All`&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;s&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;-&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;p&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;p2&lt;/span&gt;&lt;span class="p"&gt;]}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;p1&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;p2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Deuce&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="nx"&gt;s&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;p1&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;p2&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;p1N&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;p2N&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;p1&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;p2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;p1&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;p2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
        &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="s2"&gt;`Advantage &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;s&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;
        &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;`Win for &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;s&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nx"&gt;wonPoint&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;playerName&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;playerName&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;player1&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;p1&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;p2&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I've created a modern version of the Tennis-3 refactoring kata. The class calculates the tennis score for a game. You can find the full code including a test suite on &lt;a href="https://github.com/p42ai/javascript-refactoring-kata/tree/main/tennis-3-modern"&gt;GitHub&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How would you refactor it?&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>discuss</category>
      <category>beginners</category>
      <category>refactorit</category>
    </item>
    <item>
      <title>What's new in P42? Summer 2022</title>
      <dc:creator>Lars Grammel</dc:creator>
      <pubDate>Tue, 21 Jun 2022 08:41:00 +0000</pubDate>
      <link>https://dev.to/p42/whats-new-in-p42-summer-2022-summary-22nh</link>
      <guid>https://dev.to/p42/whats-new-in-p42-summer-2022-summary-22nh</guid>
      <description>&lt;p&gt;Since February, the &lt;a href="https://marketplace.visualstudio.com/items?itemName=p42ai.refactor"&gt;P42 JavaScript Assistant for Visual Studio Code&lt;/a&gt; has grown considerably and contains over 90 code assists and refactorings. The user interface has been improved based on feedback, and the JavaScript Assistant now supports Vue.js. Here are the details:&lt;/p&gt;

&lt;h2&gt;
  
  
  Vue.js Support (P42 Pro)
&lt;/h2&gt;

&lt;p&gt;You can now use code assists, refactorings, and suggestions from the P42 JavaScript Assistant inside &lt;code&gt;.vue&lt;/code&gt; files and mass refactorings updates &lt;code&gt;.vue&lt;/code&gt; files.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--LWkRN9d_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ejpzgm1e6td2cfxto1d2.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--LWkRN9d_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ejpzgm1e6td2cfxto1d2.gif" alt="P42 Vue.js Example" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  User Interface
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Keyboard Shortcuts
&lt;/h3&gt;

&lt;p&gt;The JavaScript Assistant has different default keyboard shortcuts for the code assist context menus and a "move" context menu shortcut. You can now &lt;a href="https://p42.ai/documentation/p42-for-vscode/editor-integration#keyboard-shortcuts"&gt;add custom keyboard shortcuts for any P42 code assist&lt;/a&gt;.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Context Menu&lt;/th&gt;
&lt;th&gt;Mac Shortcut&lt;/th&gt;
&lt;th&gt;Windows/Linux Shortcut&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Quick Fix&lt;/td&gt;
&lt;td&gt;
CMD + .
&lt;/td&gt;
&lt;td&gt;
CTRL + .
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Refactor&lt;/td&gt;
&lt;td&gt;
CTRL + CMD + R
&lt;/td&gt;
&lt;td&gt;
CTRL + ALT + R
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Extract&lt;/td&gt;
&lt;td&gt;
CTRL + CMD + X
&lt;/td&gt;
&lt;td&gt;
CTRL + ALT + X
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Inline&lt;/td&gt;
&lt;td&gt;
CTRL + CMD + I
&lt;/td&gt;
&lt;td&gt;
CTRL + ALT + I
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Convert&lt;/td&gt;
&lt;td&gt;
CTRL + CMD + C
&lt;/td&gt;
&lt;td&gt;
CTRL + ALT + C
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Move&lt;/td&gt;
&lt;td&gt;
CTRL + CMD + M
&lt;/td&gt;
&lt;td&gt;
CTRL + ALT + M
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Action&lt;/td&gt;
&lt;td&gt;
CTRL + CMD + A
&lt;/td&gt;
&lt;td&gt;
CTRL + ALT + A
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h3&gt;
  
  
  Suggestion Display and Panel
&lt;/h3&gt;

&lt;p&gt;The P42 refactorings suggestions are shown as hints inside the editor (underline with three dots) by default, and the suggestion side panel highlights relevant code on mouseover. When you click on a selected item in the side panel, the editor scrolls to the appropriate location.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--b0opEPo6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2egu8rzarslefwcysysm.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--b0opEPo6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2egu8rzarslefwcysysm.gif" alt="P42 Code Highlighting" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Mass Refactoring (P42 Pro)
&lt;/h3&gt;

&lt;p&gt;The &lt;a href="https://p42.ai/documentation/p42-for-vscode/mass-refactoring"&gt;mass refactoring&lt;/a&gt; dialog is now more usable. You can search the description and details, e.g., to find all ES2015 modernizations, and the refactorings are sorted alphabetically.&lt;/p&gt;

&lt;p&gt;The mass refactoring output is easier to understand and contains more information. It includes the file exclusions patterns, a progress indicator for every 50 analyzed files, and the overall refactoring time in seconds.&lt;/p&gt;

&lt;h2&gt;
  
  
  Configuration
&lt;/h2&gt;

&lt;h3&gt;
  
  
  ECMAScript Target Version
&lt;/h3&gt;

&lt;p&gt;You can &lt;a href="https://p42.ai/documentation/p42-for-vscode/configuration#platform-version"&gt;specify the target ECMAScript version in the P42 configuration file&lt;/a&gt;. Code modernizations that would require newer ECMAScript versions are hidden when you configure an older target version.&lt;/p&gt;

&lt;h3&gt;
  
  
  Hide Overlapping Code Actions
&lt;/h3&gt;

&lt;p&gt;The P42 JavaScript Assistant provides code assists that mirror and extend the functionality of code assists that come with Visual Studio Code. You can now &lt;a href="https://p42.ai/documentation/p42-for-vscode/configuration#overlapping-code-assist-visibility"&gt;configure the visibility of overlapping code assists&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Code Assists and Refactorings
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Working with Variables
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;em&gt;New&lt;/em&gt; - &lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/split-variable-declaration-and-initialization"&gt;Split Variable Declaration and Initialization&lt;/a&gt;&lt;/strong&gt;: Separate the variable initialization from its declaration.&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;New&lt;/em&gt; - &lt;strong&gt;&lt;a href="https://p42.ai/code-assist/merge-variable-declaration-and-initialization"&gt;Merge Variable Declaration and Initialization&lt;/a&gt;&lt;/strong&gt;: Convert the initial assignment of a variable into its declaration initializer.&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;New&lt;/em&gt; - &lt;strong&gt;&lt;a href="https://p42.ai/code-assist/replace-expression-with-existing-variable"&gt;Replace with existing variable&lt;/a&gt;&lt;/strong&gt;: Replace an expression with an existing variable (P42 Pro). &lt;/li&gt;
&lt;li&gt;
&lt;em&gt;New&lt;/em&gt; - &lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/push-into-initial-value-declaration"&gt;Push variable declaration into initial value&lt;/a&gt;&lt;/strong&gt;: Inlines a variable that is initialized with another variable into the declaration of that variable (P42 Pro).&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;New&lt;/em&gt; - &lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/remove-unused-variable"&gt;Remove unused variable&lt;/a&gt;&lt;/strong&gt;: Remove a variable that is not read or written.&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;Improved&lt;/em&gt; - &lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/extract-variable"&gt;Extract variable&lt;/a&gt;&lt;/strong&gt; suggests better variable names when extracting identifiers and property access expressions and automatically creates blocks when needed.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--E_W6nSyO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://p42.ai/image/blog/2022-06-20-whats-new-in-p42-summer-2022-summary/push-into-initial-variable-declaration.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--E_W6nSyO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://p42.ai/image/blog/2022-06-20-whats-new-in-p42-summer-2022-summary/push-into-initial-variable-declaration.gif" alt="Push variable declaration into initial value" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Working with Destructuring Expressions
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;em&gt;New&lt;/em&gt; - &lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/convert-to-destructuring-assignment"&gt;Convert to destructuring assignment&lt;/a&gt;&lt;/strong&gt;: Convert a variable declaration that accesses an object property to a destructuring assignment.&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;New&lt;/em&gt; - &lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/merge-into-preceding-destructuring-assignment"&gt;Merge into preceding destructuring assignment&lt;/a&gt;&lt;/strong&gt;: Combine an object destructuring assignment with its preceding sibling.&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;New&lt;/em&gt; - &lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/flatten-array-rest-property"&gt;Flatten array rest/spread property&lt;/a&gt;&lt;/strong&gt;: Merge a &lt;code&gt;...[]&lt;/code&gt; expression into the outer array literal or destructuring expression (P42 Pro).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Working with Classes
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;em&gt;New&lt;/em&gt; - &lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/move-field-initializer-into-constructor"&gt;Move field initialization into constructor&lt;/a&gt;&lt;/strong&gt;: Moves the assignment of the initial field value into the class constructor (P42 Pro).&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;New&lt;/em&gt; - &lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/move-field-initializer-into-declaration"&gt;Move initialization into field declaration&lt;/a&gt;&lt;/strong&gt;: Moves the assignment of the initial field value into the field declaration (P42 Pro).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Working with Functions
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;em&gt;New&lt;/em&gt; - &lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/convert-named-function-to-function-expression"&gt;Convert named function to function expression&lt;/a&gt;&lt;/strong&gt;: Converts a named function to a const declaration with a function expression.&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;New&lt;/em&gt; - &lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/introduce-early-return"&gt;Introduce early return / continue&lt;/a&gt;&lt;/strong&gt;: Change an if-statement into an early return or continue statement (P42 Pro).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Working with Loops and Arrays
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;em&gt;New&lt;/em&gt; - &lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/convert-loop-to-map"&gt;Convert loop to .map()&lt;/a&gt;&lt;/strong&gt;: Convert a loop with &lt;code&gt;.push()&lt;/code&gt; into a &lt;code&gt;.map()&lt;/code&gt; call (P42 Pro).&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;New&lt;/em&gt; - &lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/replace-lodash-foreach"&gt;Replace _.each and _.forEach with array.forEach&lt;/a&gt;&lt;/strong&gt;: Replace Lodash &lt;code&gt;_.each&lt;/code&gt; and &lt;code&gt;_.forEach&lt;/code&gt; with &lt;code&gt;array.forEach&lt;/code&gt; (P42 Pro).&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;Improved&lt;/em&gt; - &lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/convert-array-index-of-to-array-includes"&gt;Convert array.indexOf() into array.includes()&lt;/a&gt;&lt;/strong&gt; converts exclusion checks to &lt;code&gt;!array.includes(..)&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;Improved&lt;/em&gt; - &lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/convert-loop-to-for-of"&gt;Convert loop to for…of&lt;/a&gt;&lt;/strong&gt; supports converting &lt;code&gt;anArray.forEach&lt;/code&gt; to a for…of loop.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--HpSCk_me--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ncl1o96xmgvj9ce9ej45.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--HpSCk_me--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ncl1o96xmgvj9ce9ej45.gif" alt="Convert loop to .map()" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Working with Conditional Expressions
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;em&gt;New&lt;/em&gt; - &lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/convert-and-and-guard-to-if-statement"&gt;Convert &amp;amp;&amp;amp; to if statement&lt;/a&gt;&lt;/strong&gt;: Convert &lt;code&gt;condition &amp;amp;&amp;amp; aFunction();&lt;/code&gt; and similar expression statements into if statements.&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;Improved&lt;/em&gt; - &lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/split-if"&gt;Split if statement&lt;/a&gt;&lt;/strong&gt; supports splitting on &lt;code&gt;||&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;Improved&lt;/em&gt; - &lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/flip-operator"&gt;Flip operator&lt;/a&gt;&lt;/strong&gt; supports &lt;code&gt;+&lt;/code&gt;, &lt;code&gt;*&lt;/code&gt;, and binary operators.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Working with String and Templates
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;em&gt;New&lt;/em&gt; - &lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/convert-comparison-chain-to-array-includes"&gt;Convert string comparison chain to array.includes&lt;/a&gt;&lt;/strong&gt;: Replace &lt;code&gt;|| value === 'aString'&lt;/code&gt;&lt;code&gt;and&lt;/code&gt;&amp;amp;&amp;amp; value !== 'aString'&lt;code&gt;chains with `array.includes()&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;Improved&lt;/em&gt; - &lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/extract-substring-to-variable"&gt;Extract selected text into variable&lt;/a&gt;&lt;/strong&gt; supports extracting text and included expressions from template literals.&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;Improved&lt;/em&gt; - &lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/inline-into-template"&gt;Inline into template&lt;/a&gt;&lt;/strong&gt; supports inlining template literals into template literals.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Other Code Actions
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;em&gt;New&lt;/em&gt; - &lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/remove-console-log"&gt;Remove console.log&lt;/a&gt;&lt;/strong&gt;: Remove &lt;code&gt;console.log&lt;/code&gt; statement.&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;New&lt;/em&gt; - &lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/replace-void-0-with-undefined"&gt;Replace void 0 with undefined&lt;/a&gt;&lt;/strong&gt;: Replace &lt;code&gt;void 0&lt;/code&gt; and other constant &lt;code&gt;void&lt;/code&gt; expressions with undefined.&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;New&lt;/em&gt; - &lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/select-expression-occurrences"&gt;Select expression occurrences&lt;/a&gt;&lt;/strong&gt;: Start a multi-cursor selection on several occurrences of the same expression (P42 Pro).&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;Improved&lt;/em&gt; - Replaced the "move statement out of if-else" refactoring with new &lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/move-first-statement-out-of-if-else"&gt;Move duplicated first statement out of if-else&lt;/a&gt;&lt;/strong&gt; and &lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/move-last-statement-out-of-if-else"&gt;Move duplicated last statement out of if-else&lt;/a&gt;&lt;/strong&gt; refactorings.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--RFazRLmf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://p42.ai/image/blog/2022-06-20-whats-new-in-p42-summer-2022-summary/select-expression-occurrences.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--RFazRLmf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://p42.ai/image/blog/2022-06-20-whats-new-in-p42-summer-2022-summary/select-expression-occurrences.gif" alt="Select expression occurrences" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can follow &lt;a href="https://twitter.com/p42ai"&gt;@p42ai on Twitter&lt;/a&gt; to get notified about new features.&lt;/p&gt;

&lt;p&gt;Happy Coding!&lt;/p&gt;

</description>
      <category>vscode</category>
      <category>javascript</category>
      <category>typescript</category>
      <category>vue</category>
    </item>
    <item>
      <title>JS Refactoring Combo: Introduce Object Destructuring</title>
      <dc:creator>Lars Grammel</dc:creator>
      <pubDate>Wed, 08 Jun 2022 18:33:23 +0000</pubDate>
      <link>https://dev.to/p42/js-refactoring-combo-introduce-object-destructuring-5c0o</link>
      <guid>https://dev.to/p42/js-refactoring-combo-introduce-object-destructuring-5c0o</guid>
      <description>&lt;p&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment" rel="noopener noreferrer"&gt;Destructuring&lt;/a&gt; is a way to access array values or object properties. It can be used in variable declarations, parameters, and catch clauses. &lt;/p&gt;

&lt;p&gt;You can use destructuring to access several properties at once, making it possible to concisely unpack an object into local variables. These local variables can replace redundant property access chains and make the code easier to read.&lt;/p&gt;

&lt;h3&gt;
  
  
  Before (Example)
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;item&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="nx"&gt;items&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;totalAmount&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;price&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;amount&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;price&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;discount&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nx"&gt;totalDiscount&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;price&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;discount&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="nf"&gt;logPurchase&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;customer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;country&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
    &lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;customer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;zipCode&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
    &lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;price&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;amount&lt;/span&gt;
  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Refactoring Steps
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhh1kvw9hgclq4b8h8jx6.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhh1kvw9hgclq4b8h8jx6.gif" alt="Introduce object destructuring"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;💡  The refactoring steps are using &lt;a href="https://marketplace.visualstudio.com/items?itemName=p42ai.refactor" rel="noopener noreferrer"&gt;P42 JavaScript Assistant&lt;/a&gt; v1.113&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;a href="https://p42.ai/documentation/code-assist/extract-variable" rel="noopener noreferrer"&gt;Extract all occurrences&lt;/a&gt; of the object properties into a variable for each property. The name of the variables should match the property names.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://p42.ai/documentation/code-assist/convert-to-destructuring-assignment" rel="noopener noreferrer"&gt;Convert the variables to destructuring expressions&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Move up the variables so that they are next to each other.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://p42.ai/documentation/code-assist/merge-into-preceding-destructuring-assignment" rel="noopener noreferrer"&gt;Merge the destructuring expressions&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://p42.ai/documentation/code-assist/push-into-initial-value-declaration" rel="noopener noreferrer"&gt;Push the combined destructuring expression into the destructured variable&lt;/a&gt; (optional).&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  After (Example)
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;price&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;customer&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="nx"&gt;items&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;totalAmount&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="nx"&gt;price&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;amount&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;price&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;discount&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nx"&gt;totalDiscount&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="nx"&gt;price&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;discount&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="nf"&gt;logPurchase&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="nx"&gt;customer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;country&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
    &lt;span class="nx"&gt;customer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;zipCode&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
    &lt;span class="nx"&gt;price&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;amount&lt;/span&gt;
  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>javascript</category>
      <category>beginners</category>
      <category>vscode</category>
      <category>webdev</category>
    </item>
    <item>
      <title>85 JavaScript Code Assists for Visual Studio Code</title>
      <dc:creator>Lars Grammel</dc:creator>
      <pubDate>Mon, 30 May 2022 17:07:12 +0000</pubDate>
      <link>https://dev.to/p42/85-javascript-code-assists-for-visual-studio-code-1akh</link>
      <guid>https://dev.to/p42/85-javascript-code-assists-for-visual-studio-code-1akh</guid>
      <description>&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Code assists&lt;/strong&gt; such as refactorings, code actions, and quick fixes are another tool in this repertoire. You can use code assists to &lt;strong&gt;make higher-level language-aware changes&lt;/strong&gt;, 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.&lt;/p&gt;

&lt;p&gt;I've written an extension for Visual Studio Code called &lt;a href="https://marketplace.visualstudio.com/items?itemName=p42ai.refactor" rel="noopener noreferrer"&gt;JavaScript Assistant&lt;/a&gt; that adds 85 code assists for JavaScript and TypeScript to make your life easier. &lt;strong&gt;You can find the code assists in refactoring and quick-fix context menus or invoke them with keyboard shortcuts&lt;/strong&gt;. The JavaScript Assistant will also sometimes suggest recommended refactorings.&lt;/p&gt;

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

&lt;ul&gt;
&lt;li&gt;Core Refactorings&lt;/li&gt;
&lt;li&gt;Code Assists for React&lt;/li&gt;
&lt;li&gt;Code Assists for Logical Expressions&lt;/li&gt;
&lt;li&gt;Code Assists for Branching Statements&lt;/li&gt;
&lt;li&gt;Code Assists for Arrays and Loops&lt;/li&gt;
&lt;li&gt;Code Assists for Functions and Methods&lt;/li&gt;
&lt;li&gt;Code Assists for Strings and Template Literals&lt;/li&gt;
&lt;li&gt;Code Assists for Variables&lt;/li&gt;
&lt;li&gt;Code Assists for Syntax Conversion&lt;/li&gt;
&lt;li&gt;JavaScript Modernizations&lt;/li&gt;
&lt;li&gt;Lodash Modernizations&lt;/li&gt;
&lt;li&gt;Code Cleanups&lt;/li&gt;
&lt;li&gt;Other Code Assists&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Code assists that belong to several categories appear more than once.&lt;/p&gt;

&lt;h2&gt;
  
  
  Core Refactorings
&lt;/h2&gt;

&lt;p&gt;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:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/extract-substring-to-variable" rel="noopener noreferrer"&gt;Extract selected text into variable&lt;/a&gt;&lt;/strong&gt;: Extract the selected text (including expressions from template literals) into a &lt;code&gt;const&lt;/code&gt; variable.
&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fp42.ai%2Fimage%2Fdocumentation%2Fcode-action%2Fextract-substring-to-variable%2Fvscode-example.gif%232" alt="Extract selected text into variable"&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/extract-variable" rel="noopener noreferrer"&gt;Extract variable&lt;/a&gt;&lt;/strong&gt;: Extract one or more occurrences of an expression into a &lt;code&gt;const&lt;/code&gt; variable.
&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fp42.ai%2Fimage%2Fdocumentation%2Fcode-action%2Fextract-variable%2Fvscode-example.gif%232" alt="Extract variable"&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/inline-return" rel="noopener noreferrer"&gt;Inline return&lt;/a&gt;&lt;/strong&gt;: Convert a variable assignment to a &lt;code&gt;return&lt;/code&gt; statement.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/inline-variable" rel="noopener noreferrer"&gt;Inline variable&lt;/a&gt;&lt;/strong&gt;: Inline a variable value into its references.
&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fp42.ai%2Fimage%2Fdocumentation%2Fcode-action%2Finline-variable%2Fvscode-example.gif%232" alt="Inline variable"&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Code Assists for React
&lt;/h2&gt;

&lt;p&gt;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:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/add-braces-to-jsx-attribute" rel="noopener noreferrer"&gt;Add {...} to JSX attribute&lt;/a&gt;&lt;/strong&gt;: Add &lt;code&gt;{...}&lt;/code&gt; to JSX attribute string literal value.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/collapse-jsx-element" rel="noopener noreferrer"&gt;Collapse JSX tag&lt;/a&gt;&lt;/strong&gt;: Convert an empty JSX tag into a self-closing tag.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/expand-self-closing-jsx-element" rel="noopener noreferrer"&gt;Expand JSX tag&lt;/a&gt;&lt;/strong&gt;: Expand a self-closing JSX tag.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/extract-jsx-element" rel="noopener noreferrer"&gt;Extract React function component&lt;/a&gt;&lt;/strong&gt;: Extract JSX element or fragment into a React Function Component.
&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fp42.ai%2Fimage%2Fdocumentation%2Fcode-action%2Fextract-jsx-element%2Fvscode-example.gif%232" alt="Extract React function component"&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/remove-braces-from-jsx-attribute" rel="noopener noreferrer"&gt;Remove {...} from JSX attribute&lt;/a&gt;&lt;/strong&gt;: Remove &lt;code&gt;{...}&lt;/code&gt; from a JSX attribute expression value that contains a string literal.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/remove-unnecessary-jsx-fragment" rel="noopener noreferrer"&gt;Remove unnecessary JSX fragment&lt;/a&gt;&lt;/strong&gt;: Replace JSX Fragments &lt;code&gt;&amp;lt;&amp;gt;&amp;lt;/&amp;gt;&lt;/code&gt; that only contain a single child with that child.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/surround-with-jsx-fragment" rel="noopener noreferrer"&gt;Surround with &amp;lt;&amp;gt;...&amp;lt;/&amp;gt;&lt;/a&gt;&lt;/strong&gt;: Wrap JSX elements in a JSX fragment &lt;code&gt;&amp;lt;&amp;gt;...&amp;lt;/&amp;gt;&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Code Assists for Logical Expressions
&lt;/h2&gt;

&lt;p&gt;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:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/convert-comparison-chain-to-array-includes" rel="noopener noreferrer"&gt;Convert string comparison chain to array.includes&lt;/a&gt;&lt;/strong&gt;: Replace &lt;code&gt;|| value === 'aString'&lt;/code&gt; and &lt;code&gt;&amp;amp;&amp;amp; value !== 'aString'&lt;/code&gt;  chains with &lt;code&gt;array.includes()&lt;/code&gt;.
&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fp42.ai%2Fimage%2Fdocumentation%2Fcode-action%2Fconvert-comparison-chain-to-array-includes%2Fvscode-example.gif%232" alt="Convert string comparison chain to array.includes"&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/convert-to-optional-chaining" rel="noopener noreferrer"&gt;Convert to optional chaining&lt;/a&gt;&lt;/strong&gt;: Replace various guard expressions with the optional chaining operator (&lt;code&gt;?.&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/flip-operator" rel="noopener noreferrer"&gt;Flip operator&lt;/a&gt;&lt;/strong&gt;: Swap the left and right operands and update the operator if necessary.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/invert-condition" rel="noopener noreferrer"&gt;Invert condition&lt;/a&gt;&lt;/strong&gt;: Negate the condition of an if-statement or conditional expression and swap its content.
&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fp42.ai%2Fimage%2Fdocumentation%2Fcode-action%2Finvert-condition%2Fvscode-example.gif%232" alt="Invert condition"&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/pull-up-negation" rel="noopener noreferrer"&gt;Pull up negation&lt;/a&gt;&lt;/strong&gt;: Move the not-operator (&lt;code&gt;!&lt;/code&gt;) out of a binary expression.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/push-down-negation" rel="noopener noreferrer"&gt;Push down negation&lt;/a&gt;&lt;/strong&gt;: Push the not-operator (&lt;code&gt;!&lt;/code&gt;) into an expression and negate it.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/remove-double-negation" rel="noopener noreferrer"&gt;Remove double negation&lt;/a&gt;&lt;/strong&gt;: Remove double negation (&lt;code&gt;!!&lt;/code&gt;) expressions.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/simplify-binary-expression" rel="noopener noreferrer"&gt;Simplify binary expression&lt;/a&gt;&lt;/strong&gt;: Replace binary expression with a more straightforward equivalent expression.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/use-eq-eq-null" rel="noopener noreferrer"&gt;Use == null comparison&lt;/a&gt;&lt;/strong&gt;: Replace different nullish checks with &lt;code&gt;== null&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Code Assists for Branching Statements
&lt;/h2&gt;

&lt;p&gt;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:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/convert-and-and-guard-to-if-statement" rel="noopener noreferrer"&gt;Convert &amp;amp;&amp;amp; to if statement&lt;/a&gt;&lt;/strong&gt;: Convert &lt;code&gt;condition &amp;amp;&amp;amp; aFunction();&lt;/code&gt; and similar expression statements into if statements.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/convert-conditional-expression-to-if-else" rel="noopener noreferrer"&gt;Convert conditional expression to if-else&lt;/a&gt;&lt;/strong&gt;: Convert a conditional expression to an if-else statement.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/convert-if-else-to-conditional-expression" rel="noopener noreferrer"&gt;Convert if-else into conditional expression&lt;/a&gt;&lt;/strong&gt;: Convert an &lt;code&gt;if&lt;/code&gt;-&lt;code&gt;else&lt;/code&gt; return or assignment expression into a conditional expression.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/convert-if-else-to-switch" rel="noopener noreferrer"&gt;Convert if-else to switch&lt;/a&gt;&lt;/strong&gt;: Convert if-else statement chain with equality comparisons to switch statement.
&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fp42.ai%2Fimage%2Fdocumentation%2Fcode-action%2Fconvert-if-else-to-switch%2Fvscode-example.gif%232" alt="Convert if-else to switch"&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/merge-nested-else-if" rel="noopener noreferrer"&gt;Merge nested if inside else into else-if&lt;/a&gt;&lt;/strong&gt;: Nested single &lt;code&gt;if&lt;/code&gt; statements inside &lt;code&gt;else&lt;/code&gt; blocks can be combined into &lt;code&gt;else if&lt;/code&gt; statements.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/merge-nested-if" rel="noopener noreferrer"&gt;Merge nested if-statements&lt;/a&gt;&lt;/strong&gt;: Combine two nested &lt;code&gt;if&lt;/code&gt; statements without additional operations into a single &lt;code&gt;if&lt;/code&gt;-statement, using &lt;code&gt;&amp;amp;&amp;amp;&lt;/code&gt; to combine the conditions.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/move-first-statement-out-of-if-else" rel="noopener noreferrer"&gt;Move duplicated first statement out of if-else&lt;/a&gt;&lt;/strong&gt;: Move a first statement that appears in both the if and the else block out of the if-else statement.
&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fp42.ai%2Fimage%2Fdocumentation%2Fcode-action%2Fmove-first-statement-out-of-if-else%2Fvscode-example.gif%232" alt="Move duplicated first statement out of if-else"&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/move-last-statement-out-of-if-else" rel="noopener noreferrer"&gt;Move duplicated last statement out of if-else&lt;/a&gt;&lt;/strong&gt;: Move a last statement that appears in both the if and the else block out of the if-else statement.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/remove-empty-else-block" rel="noopener noreferrer"&gt;Remove empty else block&lt;/a&gt;&lt;/strong&gt;: Remove an empty 'else' block from an 'if' statement.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/remove-empty-if-block" rel="noopener noreferrer"&gt;Remove empty if block&lt;/a&gt;&lt;/strong&gt;: Remove an empty 'if' block from an 'if' statement. Replaces it with the 'else' block when available.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/remove-redundant-else" rel="noopener noreferrer"&gt;Remove redundant else if&lt;/a&gt;&lt;/strong&gt;: Remove redundant else-if conditions and unreachable else statements.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/remove-unnecessary-conditional-expression" rel="noopener noreferrer"&gt;Remove unnecessary conditional expression&lt;/a&gt;&lt;/strong&gt;: Replace a conditional expression with its condition or its result.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/remove-unnecessary-else" rel="noopener noreferrer"&gt;Remove unnecessary else&lt;/a&gt;&lt;/strong&gt;: Lift the else content of an &lt;code&gt;if&lt;/code&gt;-&lt;code&gt;else&lt;/code&gt; with a return statement to the outer indentation level.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/separate-condition-into-nested-if" rel="noopener noreferrer"&gt;Separate repeated condition into nested if-else&lt;/a&gt;&lt;/strong&gt;: Separate a repeated sub-condition that is fully covered into a nested if-else.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/split-if" rel="noopener noreferrer"&gt;Split if statement&lt;/a&gt;&lt;/strong&gt;: Split the condition of an if statement on &lt;code&gt;||&lt;/code&gt; or &lt;code&gt;&amp;amp;&amp;amp;&lt;/code&gt; when possible.
&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fp42.ai%2Fimage%2Fdocumentation%2Fcode-action%2Fsplit-if%2Fvscode-example.gif%232" alt="Split if statement"&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Code Assists for Arrays and Loops
&lt;/h2&gt;

&lt;p&gt;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 &lt;code&gt;for&lt;/code&gt; loops and for converting to more idiomatic array methods such as &lt;code&gt;array.includes()&lt;/code&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/convert-array-index-of-to-array-includes" rel="noopener noreferrer"&gt;Convert array.indexOf() into array.includes()&lt;/a&gt;&lt;/strong&gt;: Replace &lt;code&gt;array.indexOf()&lt;/code&gt; checks with &lt;code&gt;array.includes()&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/convert-comparison-chain-to-array-includes" rel="noopener noreferrer"&gt;Convert string comparison chain to array.includes&lt;/a&gt;&lt;/strong&gt;: Replace &lt;code&gt;|| value === 'aString'&lt;/code&gt; and &lt;code&gt;&amp;amp;&amp;amp; value !== 'aString'&lt;/code&gt;  chains with &lt;code&gt;array.includes()&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/convert-loop-to-for-each" rel="noopener noreferrer"&gt;Convert loop to .forEach&lt;/a&gt;&lt;/strong&gt;: Replace regular &lt;code&gt;for&lt;/code&gt; loops with &lt;code&gt;.forEach()&lt;/code&gt; loops.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/convert-loop-to-for-of" rel="noopener noreferrer"&gt;Convert loop to for..of&lt;/a&gt;&lt;/strong&gt;: Replace regular &lt;code&gt;for&lt;/code&gt; loops and &lt;code&gt;anArray.forEach&lt;/code&gt; loops with &lt;code&gt;for...of&lt;/code&gt; loops.
&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fp42.ai%2Fimage%2Fdocumentation%2Fcode-action%2Fconvert-loop-to-for-of%2Fvscode-example.gif%232" alt="Convert loop to for..of"&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/convert-loop-to-for-with-index" rel="noopener noreferrer"&gt;Convert loop to for&lt;/a&gt;&lt;/strong&gt;: Replace &lt;code&gt;for..of&lt;/code&gt; with a regular &lt;code&gt;for&lt;/code&gt; loop that has an index variable.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Code Assists for Functions and Methods
&lt;/h2&gt;

&lt;p&gt;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:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/add-braces-to-arrow-function" rel="noopener noreferrer"&gt;Add {…} to arrow function&lt;/a&gt;&lt;/strong&gt;: Convert arrow function expression body into a block body.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/convert-function-to-arrow-function" rel="noopener noreferrer"&gt;Convert function to arrow function&lt;/a&gt;&lt;/strong&gt;: Replace function expressions with arrow functions, a more concise syntax.
&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fp42.ai%2Fimage%2Fdocumentation%2Fcode-action%2Fconvert-function-to-arrow-function%2Fvscode-example.gif%232" alt="Convert function to arrow function"&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/convert-function-to-object-method" rel="noopener noreferrer"&gt;Convert function to object method&lt;/a&gt;&lt;/strong&gt;: Convert property assignments with functions to method declarations.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/convert-named-function-to-function-expression" rel="noopener noreferrer"&gt;Convert named function to function expression&lt;/a&gt;&lt;/strong&gt;: Converts a named function to a const declaration with a function expression.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/lift-default-into-parameter" rel="noopener noreferrer"&gt;Lift default into parameter&lt;/a&gt;&lt;/strong&gt;: Replace default value assignment expressions with default parameter values.
&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fp42.ai%2Fimage%2Fdocumentation%2Fcode-action%2Flift-default-into-parameter%2Fvscode-example.gif%232" alt="Lift default into parameter"&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/push-parameter-into-iife" rel="noopener noreferrer"&gt;Push parameter into IIFE/IIAF&lt;/a&gt;&lt;/strong&gt;: Push a parameter of an immediately-invoked function expressions (IIFEs) or an immediately-invoked arrow functions (IIAFs) into the function body.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/remove-braces-from-arrow-function" rel="noopener noreferrer"&gt;Remove {…} from arrow function&lt;/a&gt;&lt;/strong&gt;: Convert an arrow function block body into an expression body.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/remove-iife" rel="noopener noreferrer"&gt;Remove IIFE/IIAF&lt;/a&gt;&lt;/strong&gt;: Remove immediately-invoked function expressions (IIFEs) and immediately-invoked arrow functions (IIAFs) without parameters.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Code Assists for Strings and Template Literals
&lt;/h2&gt;

&lt;p&gt;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:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/convert-comparison-chain-to-array-includes" rel="noopener noreferrer"&gt;Convert string comparison chain to array.includes&lt;/a&gt;&lt;/strong&gt;: Replace &lt;code&gt;|| value === 'aString'&lt;/code&gt; and &lt;code&gt;&amp;amp;&amp;amp; value !== 'aString'&lt;/code&gt;  chains with &lt;code&gt;array.includes()&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/convert-string-to-template-literal" rel="noopener noreferrer"&gt;Convert string to template literal&lt;/a&gt;&lt;/strong&gt;: Convert a string to a basic template literal without expressions.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/convert-template-literal-to-string" rel="noopener noreferrer"&gt;Convert template literal to string&lt;/a&gt;&lt;/strong&gt;: Convert a simple template literal without expressions into a string.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/extract-substring-to-variable" rel="noopener noreferrer"&gt;Extract selected text into variable&lt;/a&gt;&lt;/strong&gt;: Extract the selected text (including expressions from template literals) into a &lt;code&gt;const&lt;/code&gt; variable.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/inline-into-template" rel="noopener noreferrer"&gt;Inline into template&lt;/a&gt;&lt;/strong&gt;: Inline a string or a basic template literal into an outer template literal.
&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fp42.ai%2Fimage%2Fdocumentation%2Fcode-action%2Finline-into-template%2Fvscode-example.gif%232" alt="Inline into template"&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/remove-unnecessary-template" rel="noopener noreferrer"&gt;Remove unnecessary template literal&lt;/a&gt;&lt;/strong&gt;: Simplify a template literal with a single inner expression and no prefix or suffix.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/use-string-ends-with" rel="noopener noreferrer"&gt;Use string.endsWith()&lt;/a&gt;&lt;/strong&gt;: &lt;code&gt;string.endsWith()&lt;/code&gt; checks if a string ends with another string.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/use-string-starts-with" rel="noopener noreferrer"&gt;Use string.startsWith()&lt;/a&gt;&lt;/strong&gt;: &lt;code&gt;string.startsWith()&lt;/code&gt; checks if a string starts with another string.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/use-template-literal" rel="noopener noreferrer"&gt;Merge string concatenation&lt;/a&gt;&lt;/strong&gt;: Merge string and template literal concatenation into a single template literal or string.
&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fp42.ai%2Fimage%2Fdocumentation%2Fcode-action%2Fuse-template-literal%2Fvscode-example.gif%232" alt="Merge string concatenation"&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Code Assists for Variables
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/convert-let-to-const" rel="noopener noreferrer"&gt;Convert let to const&lt;/a&gt;&lt;/strong&gt;: Replace &lt;code&gt;let&lt;/code&gt; declarations that have no re-assignment with &lt;code&gt;const&lt;/code&gt; declarations.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/convert-to-destructuring-assignment" rel="noopener noreferrer"&gt;Convert to destructuring assignment&lt;/a&gt;&lt;/strong&gt;: Convert a variable declaration that accesses an object property to a destructuring assignment.
&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fp42.ai%2Fimage%2Fdocumentation%2Fcode-action%2Fconvert-to-destructuring-assignment%2Fvscode-example.gif%232" alt="Convert to destructuring assignment"&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/extract-variable" rel="noopener noreferrer"&gt;Extract variable&lt;/a&gt;&lt;/strong&gt;: Extract one or more occurrences of an expression into a &lt;code&gt;const&lt;/code&gt; variable.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/inline-return" rel="noopener noreferrer"&gt;Inline return&lt;/a&gt;&lt;/strong&gt;: Convert a variable assignment to a &lt;code&gt;return&lt;/code&gt; statement.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/lift-default-into-parameter" rel="noopener noreferrer"&gt;Lift default into parameter&lt;/a&gt;&lt;/strong&gt;: Replace default value assignment expressions with default parameter values.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/merge-into-preceding-destructuring-assignment" rel="noopener noreferrer"&gt;Merge into preceding destructuring assignment&lt;/a&gt;&lt;/strong&gt;: Combine an object destructuring assignment with its preceding sibling.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/merge-variable-declaration-and-initialization" rel="noopener noreferrer"&gt;Merge variable declaration and initialization&lt;/a&gt;&lt;/strong&gt;: Convert the initial assignment of a variable into its declaration initializer.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/move-field-initializer-into-constructor" rel="noopener noreferrer"&gt;Move field initialization into constructor&lt;/a&gt;&lt;/strong&gt;: Moves the assignment of the initial field value into the class constructor.
&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fp42.ai%2Fimage%2Fdocumentation%2Fcode-action%2Fmove-field-initializer-into-constructor%2Fvscode-example.gif%232" alt="Move field initialization into constructor"&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/move-field-initializer-into-declaration" rel="noopener noreferrer"&gt;Move initialization into field declaration&lt;/a&gt;&lt;/strong&gt;: Moves the assignment of the initial field value into the field declaration.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/push-parameter-into-iife" rel="noopener noreferrer"&gt;Push parameter into IIFE/IIAF&lt;/a&gt;&lt;/strong&gt;: Push a parameter of an immediately-invoked function expressions (IIFEs) or an immediately-invoked arrow functions (IIAFs) into the function body.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/remove-unused-variable" rel="noopener noreferrer"&gt;Remove unused variable&lt;/a&gt;&lt;/strong&gt;: Remove a variable that is not read or written.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/replace-var-with-let-and-const" rel="noopener noreferrer"&gt;Convert var to let or const&lt;/a&gt;&lt;/strong&gt;: Replace &lt;code&gt;var&lt;/code&gt; with block-scoped variables &lt;code&gt;let&lt;/code&gt; and &lt;code&gt;const&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/split-variable-declaration" rel="noopener noreferrer"&gt;Split variable declaration sequence&lt;/a&gt;&lt;/strong&gt;: Convert declarations with multiple variables into separate declarations for each variable.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/split-variable-declaration-and-initialization" rel="noopener noreferrer"&gt;Split variable declaration and initialization&lt;/a&gt;&lt;/strong&gt;: Separate the variable initialization from its declaration.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/use-nullish-coalescence-in-default-expression" rel="noopener noreferrer"&gt;Use nullish coalescence in default expression&lt;/a&gt;&lt;/strong&gt;: Replace default value expression with nullish coalescing operator (&lt;code&gt;??&lt;/code&gt;) expressions.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Code Assists for Syntax Conversion
&lt;/h2&gt;

&lt;p&gt;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:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/add-braces-to-arrow-function" rel="noopener noreferrer"&gt;Add {…} to arrow function&lt;/a&gt;&lt;/strong&gt;: Convert arrow function expression body into a block body.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/add-braces-to-jsx-attribute" rel="noopener noreferrer"&gt;Add {…} to JSX attribute&lt;/a&gt;&lt;/strong&gt;: Add &lt;code&gt;{…}&lt;/code&gt; to JSX attribute string literal value.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/add-numeric-separator" rel="noopener noreferrer"&gt;Add numeric separator&lt;/a&gt;&lt;/strong&gt;: Increase the readability of long numbers and uncommon number formats by adding underscore separators.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/collapse-jsx-element" rel="noopener noreferrer"&gt;Collapse JSX tag&lt;/a&gt;&lt;/strong&gt;: Convert an empty JSX tag into a self-closing tag.
&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fp42.ai%2Fimage%2Fdocumentation%2Fcode-action%2Fcollapse-jsx-element%2Fvscode-example.gif%232" alt="Collapse JSX tag"&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/collapse-property-into-shorthand" rel="noopener noreferrer"&gt;Collapse object property into shorthand&lt;/a&gt;&lt;/strong&gt;: Shorten object properties when the property name is the same as the property value.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/convert-bracket-notation-property-access-to-dot-notation" rel="noopener noreferrer"&gt;Convert property access to dot notation&lt;/a&gt;&lt;/strong&gt;: Convert bracket notation property access &lt;code&gt;o['a']&lt;/code&gt; into dot notation property access &lt;code&gt;o.a&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/convert-dot-notation-property-access-to-bracket-notation" rel="noopener noreferrer"&gt;Convert property access to bracket notation&lt;/a&gt;&lt;/strong&gt;: Convert dot notation property access &lt;code&gt;o.a&lt;/code&gt; into bracket notation property access &lt;code&gt;o['a']&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/expand-self-closing-jsx-element" rel="noopener noreferrer"&gt;Expand JSX tag&lt;/a&gt;&lt;/strong&gt;: Expand a self-closing JSX tag.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/expand-shorthand-property" rel="noopener noreferrer"&gt;Expand shorthand property&lt;/a&gt;&lt;/strong&gt;: Expand a shorthand object property (e.g. &lt;code&gt;{ a }&lt;/code&gt;) to a regular property (e.g. &lt;code&gt;{ a: a }&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/merge-variable-declaration-and-initialization" rel="noopener noreferrer"&gt;Merge variable declaration and initialization&lt;/a&gt;&lt;/strong&gt;: Convert the initial assignment of a variable into its declaration initializer.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/pull-operator-out-of-assignment" rel="noopener noreferrer"&gt;Pull operator out of assignment&lt;/a&gt;&lt;/strong&gt;: Move an operator out of an assignment into a binary expression.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/push-operator-into-assignment" rel="noopener noreferrer"&gt;Push operator into assignment&lt;/a&gt;&lt;/strong&gt;: Move an operator from a binary expression into an assignment operator, e.g., &lt;code&gt;+=&lt;/code&gt;.
&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fp42.ai%2Fimage%2Fdocumentation%2Fcode-action%2Fpush-operator-into-assignment%2Fvscode-example.gif%232" alt="Push operator into assignment"&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/remove-braces-from-arrow-function" rel="noopener noreferrer"&gt;Remove {…} from arrow function&lt;/a&gt;&lt;/strong&gt;: Convert an arrow function block body into an expression body.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/remove-braces-from-jsx-attribute" rel="noopener noreferrer"&gt;Remove {…} from JSX attribute&lt;/a&gt;&lt;/strong&gt;: Remove &lt;code&gt;{…}&lt;/code&gt; from a JSX attribute expression value that contains a string literal.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  JavaScript Modernizations
&lt;/h2&gt;

&lt;p&gt;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:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/add-numeric-separator" rel="noopener noreferrer"&gt;Add numeric separator&lt;/a&gt;&lt;/strong&gt;: Increase the readability of long numbers and uncommon number formats by adding underscore separators.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/collapse-property-into-shorthand" rel="noopener noreferrer"&gt;Collapse object property into shorthand&lt;/a&gt;&lt;/strong&gt;: Shorten object properties when the property name is the same as the property value.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/convert-apply-to-spread-syntax" rel="noopener noreferrer"&gt;Convert .apply() to spread syntax&lt;/a&gt;&lt;/strong&gt;: Replace &lt;code&gt;.apply()&lt;/code&gt; calls with the spread operator &lt;code&gt;...&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/convert-array-index-of-to-array-includes" rel="noopener noreferrer"&gt;Convert array.indexOf() into array.includes()&lt;/a&gt;&lt;/strong&gt;: Replace &lt;code&gt;array.indexOf()&lt;/code&gt; checks with &lt;code&gt;array.includes()&lt;/code&gt;.
&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fp42.ai%2Fimage%2Fdocumentation%2Fcode-action%2Fconvert-array-index-of-to-array-includes%2Fvscode-example.gif%232" alt="Convert array.indexOf() into array.includes()"&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/convert-comparison-chain-to-array-includes" rel="noopener noreferrer"&gt;Convert string comparison chain to array.includes&lt;/a&gt;&lt;/strong&gt;: Replace &lt;code&gt;|| value === 'aString'&lt;/code&gt; and &lt;code&gt;&amp;amp;&amp;amp; value !== 'aString'&lt;/code&gt;  chains with &lt;code&gt;array.includes()&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/convert-function-to-arrow-function" rel="noopener noreferrer"&gt;Convert function to arrow function&lt;/a&gt;&lt;/strong&gt;: Replace function expressions with arrow functions, a more concise syntax.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/convert-function-to-object-method" rel="noopener noreferrer"&gt;Convert function to object method&lt;/a&gt;&lt;/strong&gt;: Convert property assignments with functions to method declarations.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/convert-loop-to-for-of" rel="noopener noreferrer"&gt;Convert loop to for..of&lt;/a&gt;&lt;/strong&gt;: Replace regular &lt;code&gt;for&lt;/code&gt; loops and &lt;code&gt;anArray.forEach&lt;/code&gt; loops with &lt;code&gt;for...of&lt;/code&gt; loops.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/convert-math-pow-to-exponentiation" rel="noopener noreferrer"&gt;Convert Math.pow to exponentiation operator&lt;/a&gt;&lt;/strong&gt;: Use the exponentiation operator &lt;code&gt;**&lt;/code&gt; instead of &lt;code&gt;Math.pow()&lt;/code&gt;.
&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fp42.ai%2Fimage%2Fdocumentation%2Fcode-action%2Fconvert-math-pow-to-exponentiation%2Fvscode-example.gif%232" alt="Convert Math.pow to exponentiation operator"&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/convert-string-to-template-literal" rel="noopener noreferrer"&gt;Convert string to template literal&lt;/a&gt;&lt;/strong&gt;: Convert a string to a basic template literal without expressions.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/convert-to-destructuring-assignment" rel="noopener noreferrer"&gt;Convert to destructuring assignment&lt;/a&gt;&lt;/strong&gt;: Convert a variable declaration that accesses an object property to a destructuring assignment.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/convert-to-optional-chaining" rel="noopener noreferrer"&gt;Convert to optional chaining&lt;/a&gt;&lt;/strong&gt;: Replace various guard expressions with the optional chaining operator (&lt;code&gt;?.&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/lift-default-into-parameter" rel="noopener noreferrer"&gt;Lift default into parameter&lt;/a&gt;&lt;/strong&gt;: Replace default value assignment expressions with default parameter values.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/replace-var-with-let-and-const" rel="noopener noreferrer"&gt;Convert var to let or const&lt;/a&gt;&lt;/strong&gt;: Replace &lt;code&gt;var&lt;/code&gt; with block-scoped variables &lt;code&gt;let&lt;/code&gt; and &lt;code&gt;const&lt;/code&gt;.
&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fp42.ai%2Fimage%2Fdocumentation%2Fcode-action%2Freplace-var-with-let-and-const%2Fvscode-example.gif%232" alt="Convert var to let or const"&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/replace-void-0-with-undefined" rel="noopener noreferrer"&gt;Replace void 0 with undefined&lt;/a&gt;&lt;/strong&gt;: Replace &lt;code&gt;void 0&lt;/code&gt; and other constant &lt;code&gt;void&lt;/code&gt; expressions with &lt;code&gt;undefined&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/use-eq-eq-null" rel="noopener noreferrer"&gt;Use == null comparison&lt;/a&gt;&lt;/strong&gt;: Replace different nullish checks with &lt;code&gt;== null&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/use-nullish-coalescence-in-default-expression" rel="noopener noreferrer"&gt;Use nullish coalescence in default expression&lt;/a&gt;&lt;/strong&gt;: Replace default value expression with nullish coalescing operator (&lt;code&gt;??&lt;/code&gt;) expressions.
&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fp42.ai%2Fimage%2Fdocumentation%2Fcode-action%2Fuse-nullish-coalescence-in-default-expression%2Fvscode-example.gif%232" alt="Use nullish coalescence in default expression"&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/use-string-ends-with" rel="noopener noreferrer"&gt;Use string.endsWith()&lt;/a&gt;&lt;/strong&gt;: &lt;code&gt;string.endsWith()&lt;/code&gt; checks if a string ends with another string.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/use-string-starts-with" rel="noopener noreferrer"&gt;Use string.startsWith()&lt;/a&gt;&lt;/strong&gt;: &lt;code&gt;string.startsWith()&lt;/code&gt; checks if a string starts with another string.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/use-template-literal" rel="noopener noreferrer"&gt;Merge string concatenation&lt;/a&gt;&lt;/strong&gt;: Merge string and template literal concatenation into a single template literal or string.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Lodash Modernizations
&lt;/h2&gt;

&lt;p&gt;With the introduction of various collection helpers and new syntax in ES6 and more recent JavaScript versions, some &lt;a href="https://lodash.com/" rel="noopener noreferrer"&gt;Lodash&lt;/a&gt; functions have become somewhat redundant.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/replace-lodash-every-with-javascript-array-every" rel="noopener noreferrer"&gt;Replace _.every with array.every&lt;/a&gt;&lt;/strong&gt;: Replace Lodash &lt;code&gt;_.every&lt;/code&gt; with &lt;code&gt;array.every&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/replace-lodash-filter-with-javascript-array-filter" rel="noopener noreferrer"&gt;Replace _.filter with array.filter&lt;/a&gt;&lt;/strong&gt;: Replace Lodash &lt;code&gt;_.filter&lt;/code&gt; with &lt;code&gt;array.filter&lt;/code&gt;.
&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fp42.ai%2Fimage%2Fdocumentation%2Fcode-action%2Freplace-lodash-filter-with-javascript-array-filter%2Fvscode-example.gif%232" alt="Replace _.filter with array.filter"&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/replace-lodash-foreach" rel="noopener noreferrer"&gt;Replace _.each and _.forEach with array.forEach&lt;/a&gt;&lt;/strong&gt;: Replace Lodash &lt;code&gt;_.each&lt;/code&gt; and &lt;code&gt;_.forEach&lt;/code&gt; with &lt;code&gt;array.forEach&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/replace-lodash-map-with-javascript-array-map" rel="noopener noreferrer"&gt;Replace _.map with array.map&lt;/a&gt;&lt;/strong&gt;: Replace Lodash &lt;code&gt;_.map&lt;/code&gt; with &lt;code&gt;array.map&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/replace-lodash-noop-with-arrow-function" rel="noopener noreferrer"&gt;Replace _.noop with arrow Function&lt;/a&gt;&lt;/strong&gt;: Replace &lt;code&gt;_.noop&lt;/code&gt; with &lt;code&gt;() =&amp;gt; undefined&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/replace-lodash-some-with-javascript-array-some" rel="noopener noreferrer"&gt;Replace _.some with array.some&lt;/a&gt;&lt;/strong&gt;: Replace Lodash &lt;code&gt;_.some&lt;/code&gt; with &lt;code&gt;array.some&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Code Cleanups
&lt;/h2&gt;

&lt;p&gt;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:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/remove-console-log" rel="noopener noreferrer"&gt;Remove console.log&lt;/a&gt;&lt;/strong&gt;: Remove console.log statement.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/remove-double-negation" rel="noopener noreferrer"&gt;Remove double negation&lt;/a&gt;&lt;/strong&gt;: Remove double negation (&lt;code&gt;!!&lt;/code&gt;) expressions.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/remove-empty-else-block" rel="noopener noreferrer"&gt;Remove empty else block&lt;/a&gt;&lt;/strong&gt;: Remove an empty 'else' block from an 'if' statement.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/remove-empty-if-block" rel="noopener noreferrer"&gt;Remove empty if block&lt;/a&gt;&lt;/strong&gt;: Remove an empty 'if' block from an 'if' statement. Replaces it with the 'else' block when available.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/remove-iife" rel="noopener noreferrer"&gt;Remove IIFE/IIAF&lt;/a&gt;&lt;/strong&gt;: Remove immediately-invoked function expressions (IIFEs) and immediately-invoked arrow functions (IIAFs) without parameters.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/remove-redundant-else" rel="noopener noreferrer"&gt;Remove redundant else if&lt;/a&gt;&lt;/strong&gt;: Remove redundant else-if conditions and unreachable else statements.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/remove-unnecessary-conditional-expression" rel="noopener noreferrer"&gt;Remove unnecessary conditional expression&lt;/a&gt;&lt;/strong&gt;: Replace a conditional expression with its condition or its result.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/remove-unnecessary-else" rel="noopener noreferrer"&gt;Remove unnecessary else&lt;/a&gt;&lt;/strong&gt;: Lift the else content of an &lt;code&gt;if&lt;/code&gt;-&lt;code&gt;else&lt;/code&gt; with a return statement to the outer indentation level.
&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fp42.ai%2Fimage%2Fdocumentation%2Fcode-action%2Fremove-unnecessary-else%2Fvscode-example.gif%232" alt="Remove unnecessary else"&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/remove-unnecessary-expression-statement" rel="noopener noreferrer"&gt;Remove unnecessary expression statement&lt;/a&gt;&lt;/strong&gt;: Remove an expression statement that has no side-effects.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/remove-unnecessary-jsx-fragment" rel="noopener noreferrer"&gt;Remove unnecessary JSX fragment&lt;/a&gt;&lt;/strong&gt;: Replace JSX Fragments &lt;code&gt;&amp;lt;&amp;gt;&amp;lt;/&amp;gt;&lt;/code&gt; that only contain a single child with that child.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/remove-unnecessary-template" rel="noopener noreferrer"&gt;Remove unnecessary template literal&lt;/a&gt;&lt;/strong&gt;: Simplify a template literal with a single inner expression and no prefix or suffix.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/remove-unused-variable" rel="noopener noreferrer"&gt;Remove unused variable&lt;/a&gt;&lt;/strong&gt;: Remove a variable that is not read or written.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/replace-void-0-with-undefined" rel="noopener noreferrer"&gt;Replace void 0 with undefined&lt;/a&gt;&lt;/strong&gt;: Replace &lt;code&gt;void 0&lt;/code&gt; and other constant &lt;code&gt;void&lt;/code&gt; expressions with &lt;code&gt;undefined&lt;/code&gt;.
&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fp42.ai%2Fimage%2Fdocumentation%2Fcode-action%2Freplace-void-0-with-undefined%2Fvscode-example.gif%232" alt="Replace void 0 with undefined"&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/simplify-binary-expression" rel="noopener noreferrer"&gt;Simplify binary expression&lt;/a&gt;&lt;/strong&gt;: Replace binary expression with a more straightforward equivalent expression.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Other Code Assists
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/insert-console-log" rel="noopener noreferrer"&gt;Insert console.log for variable&lt;/a&gt;&lt;/strong&gt;: Insert a 'console.log' statement for a selected variable when possible.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://p42.ai/documentation/code-assist/surround-with-try-catch" rel="noopener noreferrer"&gt;Surround with try…catch&lt;/a&gt;&lt;/strong&gt;: Surround a sequence of statements in a &lt;code&gt;try…catch&lt;/code&gt; block.
&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fp42.ai%2Fimage%2Fdocumentation%2Fcode-action%2Fsurround-with-try-catch%2Fvscode-example.gif%232" alt="Surround with try…catch"&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;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. &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;💡  If you want to give &lt;a href="https://marketplace.visualstudio.com/items?itemName=p42ai.refactor" rel="noopener noreferrer"&gt;JavaScript Assistant&lt;/a&gt; a try, you can find it on the &lt;a href="https://marketplace.visualstudio.com/items?itemName=p42ai.refactor" rel="noopener noreferrer"&gt;Visual Studio Code marketplace&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>vscode</category>
      <category>javascript</category>
      <category>typescript</category>
      <category>beginners</category>
    </item>
    <item>
      <title>JS Refactoring Combo: Inline Function as Method</title>
      <dc:creator>Lars Grammel</dc:creator>
      <pubDate>Sat, 28 May 2022 11:02:31 +0000</pubDate>
      <link>https://dev.to/p42/js-refactoring-combo-inline-named-function-as-method-hkf</link>
      <guid>https://dev.to/p42/js-refactoring-combo-inline-named-function-as-method-hkf</guid>
      <description>&lt;p&gt;Sometimes functions are only used as property values. In such cases, you can convert the functions into methods.&lt;/p&gt;

&lt;h3&gt;
  
  
  Before (Example)
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;aFunction&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;aParameter&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;doSomething&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;aParameter&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;anObject&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;aMethod&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;aFunction&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Refactoring Steps
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--rGGEH7uS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9sqgvcf055903pjgtau9.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--rGGEH7uS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9sqgvcf055903pjgtau9.gif" alt="Inline Named Function as Method" width="635" height="316"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;💡  The refactoring steps are using &lt;a href="https://marketplace.visualstudio.com/items?itemName=p42ai.refactor"&gt;P42 JavaScript Assistant&lt;/a&gt; v1.109&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ol&gt;
&lt;li&gt;&lt;a href="https://p42.ai/documentation/code-assist/convert-named-function-to-function-expression"&gt;Convert the named function into a variable that contains the function expression&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://p42.ai/documentation/code-assist/inline-variable"&gt;Inline the variable&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://p42.ai/documentation/code-assist/convert-function-to-object-method"&gt;Convert the function to an object method&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  After (Example)
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;anObject&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;aMethod&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;aParameter&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;doSomething&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;aParameter&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>javascript</category>
      <category>tutorial</category>
      <category>programming</category>
      <category>beginners</category>
    </item>
    <item>
      <title>You don't need void 0 in JavaScript</title>
      <dc:creator>Lars Grammel</dc:creator>
      <pubDate>Tue, 10 May 2022 09:42:51 +0000</pubDate>
      <link>https://dev.to/p42/you-dont-need-void-0-663</link>
      <guid>https://dev.to/p42/you-dont-need-void-0-663</guid>
      <description>&lt;p&gt;In JavaScript code, especially in older legacy code, you sometimes find the expression &lt;code&gt;void 0&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;The &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/void"&gt;void operator&lt;/a&gt; evaluates an expression and returns the primitive value &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined"&gt;undefined&lt;/a&gt;. &lt;code&gt;void 0&lt;/code&gt; evaluates &lt;code&gt;0&lt;/code&gt;, which does nothing, and then returns &lt;code&gt;undefined&lt;/code&gt;. It is effectively an alias for &lt;code&gt;undefined&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why is void 0 used as an alias for undefined?
&lt;/h2&gt;

&lt;p&gt;One of JavaScript's quirks is that &lt;code&gt;undefined&lt;/code&gt; is not a reserved keyword. Instead, it is a property of the &lt;a href="https://developer.mozilla.org/en-US/docs/Glossary/Global_object"&gt;global object&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Before ES5 (2009), it was possible to modify the &lt;code&gt;undefined&lt;/code&gt; global property, which could lead to unexpected behavior for &lt;code&gt;undefined&lt;/code&gt;.&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;Consider the following example (which does not work in modern JavaScript engines):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Pre-ES5 example - does not work in modern JS engines:&lt;/span&gt;

&lt;span class="c1"&gt;// changes property 'undefined' on the global object:&lt;/span&gt;
&lt;span class="kc"&gt;undefined&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;something else&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 

&lt;span class="c1"&gt;// potentially in some other JavaScript file or script section:&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;aVariable&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="kc"&gt;undefined&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// aVariable is equal to "something else", &lt;/span&gt;
  &lt;span class="c1"&gt;// but not to the primitive value 'undefined'&lt;/span&gt;
  &lt;span class="nx"&gt;doSomething&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Modifying the &lt;code&gt;undefined&lt;/code&gt; global could even happen in 3rd party code, e.g., libraries imported via the script tag. Since &lt;code&gt;void 0&lt;/code&gt; always returns the actual primitive value &lt;code&gt;undefined&lt;/code&gt;, it was commonly used before ES5 to make the code failsafe against the re-definition of the &lt;code&gt;undefined&lt;/code&gt; global property.&lt;/p&gt;

&lt;h2&gt;
  
  
  The global property 'undefined' after ES5
&lt;/h2&gt;

&lt;p&gt;The problem that &lt;code&gt;undefined&lt;/code&gt; could be modified on the global object was so big that the JavaScript standard was changed.&lt;br&gt;
&lt;strong&gt;With ES5, the global property &lt;code&gt;undefined&lt;/code&gt; became read-only.&lt;/strong&gt; Attempting to change the value does nothing in modern JavaScript:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;globalThis&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="kc"&gt;undefined&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;something else&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;undefined&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// prints undefined in modern browsers&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Undefined can still be shadowed by a local variable
&lt;/h2&gt;

&lt;p&gt;However, while changing the &lt;code&gt;undefined&lt;/code&gt; global property is no longer possible, &lt;code&gt;undefined&lt;/code&gt; is still not a reserved keyword in JavaScript. Therefore it can still be shadowed by a local variable:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="kc"&gt;undefined&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;something else&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;check&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;aVariable&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// void 0 is needed here&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Having a local variable with the name &lt;code&gt;undefined&lt;/code&gt; is a pitfall that you want to avoid. The &lt;a href="https://eslint.org/docs/rules/no-undefined"&gt;ESLint rule no-undefined&lt;/a&gt; disallows the use of undefined as a variable name and prevents shadowing issues.&lt;/p&gt;

&lt;h2&gt;
  
  
  Can void 0 help reduce the bundle size?
&lt;/h2&gt;

&lt;p&gt;The expression &lt;code&gt;void 0&lt;/code&gt; is shorter than &lt;code&gt;undefined&lt;/code&gt;. JavaScript bundle sizes are essential for creating websites that load quickly, and shaving off a few bytes can help. &lt;/p&gt;

&lt;p&gt;However, it is best to &lt;strong&gt;leave basic code size optimizations to minifiers&lt;/strong&gt; such as &lt;a href="https://github.com/terser/terser"&gt;Terser&lt;/a&gt; as part of the product bundling process. They can perform many different optimizations, and the source code remains more readable without any manual code size optimizations like using &lt;code&gt;void 0&lt;/code&gt; instead of &lt;code&gt;undefined&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Avoid void 0 in modern JavaScript
&lt;/h2&gt;

&lt;p&gt;To summarize, in modern browsers and JavaScript engines, there is no reason to use &lt;code&gt;void 0&lt;/code&gt; any longer:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;the global property &lt;code&gt;undefined&lt;/code&gt; cannot be changed in ES5 and newer environments&lt;/li&gt;
&lt;li&gt;local variables with the name &lt;code&gt;undefined&lt;/code&gt; can be disallowed with the &lt;a href="https://eslint.org/docs/rules/no-undefined"&gt;ESLint rule no-undefined&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;minifiers can replace &lt;code&gt;undefined&lt;/code&gt; with &lt;code&gt;void 0&lt;/code&gt; when creating the production bundle&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;On the contrary, &lt;code&gt;void 0&lt;/code&gt; makes JavaSCript code harder to read and understand because you need to know the meaning of &lt;code&gt;void 0&lt;/code&gt; and process different terms (&lt;code&gt;void 0&lt;/code&gt;, &lt;code&gt;undefined&lt;/code&gt;) for the same concept (&lt;code&gt;undefined&lt;/code&gt;).&lt;/p&gt;

&lt;p&gt;TLDR: &lt;strong&gt;You can use &lt;code&gt;undefined&lt;/code&gt; and remove the unnecessary &lt;code&gt;void 0&lt;/code&gt; complication.&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>beginners</category>
      <category>programming</category>
    </item>
    <item>
      <title>JS Refactoring Combo: Extract Array Constant From String Comparison Chain</title>
      <dc:creator>Lars Grammel</dc:creator>
      <pubDate>Fri, 06 May 2022 14:55:23 +0000</pubDate>
      <link>https://dev.to/p42/javascript-refactoring-combo-extract-array-constant-from-string-comparison-chain-3bm2</link>
      <guid>https://dev.to/p42/javascript-refactoring-combo-extract-array-constant-from-string-comparison-chain-3bm2</guid>
      <description>&lt;p&gt;When a variable is compared against a string value, the easiest way to start is with a &lt;code&gt;variable === "value"&lt;/code&gt; or &lt;code&gt;variable !== "value"&lt;/code&gt; comparison. Over time, these can grow into longer sequences, e.g. &lt;code&gt;variable === "value1" || variable === "value2" || variable === "value3"&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The values that the variable is compared to are often a meaningful collection on their own. Refactoring them into an array and using &lt;code&gt;array.includes(variable)&lt;/code&gt; can facilitate reuse and extension, and a meaningful array name can make it easier to understand the code.&lt;/p&gt;

&lt;h3&gt;
  
  
  Before (Example)
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;extension&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;js&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; 
    &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;extension&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;ts&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; 
    &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;extension&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;tsx&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;handleUnsupportedExtension&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;extension&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Refactoring Steps
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--fcIxPq_5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ydgi0boznr3un9cso5zx.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--fcIxPq_5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ydgi0boznr3un9cso5zx.gif" alt="Extract array constant from string comparison chain" width="635" height="316"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;💡  The refactoring steps are using &lt;a href="https://marketplace.visualstudio.com/items?itemName=p42ai.refactor"&gt;P42 JavaScript Assistant&lt;/a&gt; v1.105&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ol&gt;
&lt;li&gt;&lt;a href="https://p42.ai/documentation/code-assist/convert-comparison-chain-to-array-includes"&gt;Convert string comparison chain to array.includes&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://p42.ai/documentation/code-assist/extract-variable"&gt;Extract the array into a variable&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Move the extracted array variable, e.g., to the top of the file (not shown)&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  After (Example)
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;SUPPORTED_EXTENSIONS&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;js&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;ts&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;tsx&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;SUPPORTED_EXTENSIONS&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;includes&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;extension&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;handleUnsupportedExtension&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;extension&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>javascript</category>
      <category>beginners</category>
      <category>webdev</category>
      <category>programming</category>
    </item>
    <item>
      <title>JS Refactoring Gotchas: 5 Ways Converting to Optional Chaining Can Break Your Code</title>
      <dc:creator>Lars Grammel</dc:creator>
      <pubDate>Wed, 04 May 2022 13:02:56 +0000</pubDate>
      <link>https://dev.to/p42/5-ways-that-converting-to-optional-chaining-can-break-your-javascript-code-153b</link>
      <guid>https://dev.to/p42/5-ways-that-converting-to-optional-chaining-can-break-your-javascript-code-153b</guid>
      <description>&lt;p&gt;&lt;strong&gt;The &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Optional_chaining"&gt;optional chaining&lt;/a&gt; operator &lt;code&gt;.?&lt;/code&gt; returns the value of an object property when the object is available and &lt;code&gt;undefined&lt;/code&gt; otherwise.&lt;/strong&gt; It is similar to the standard &lt;code&gt;.&lt;/code&gt; chaining operator, with an added check if the object is defined (i.e., not &lt;a href="https://developer.mozilla.org/en-US/docs/Glossary/Nullish"&gt;nullish&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;The optional chaining operator lets you &lt;strong&gt;write concise and safe chains of connected objects&lt;/strong&gt; when some of those objects can be &lt;code&gt;null&lt;/code&gt; or &lt;code&gt;undefined&lt;/code&gt;. Before the introduction of optional chaining in ES2020, the &lt;code&gt;&amp;amp;&amp;amp;&lt;/code&gt; operator was often used to check if an object is available (&lt;code&gt;obj &amp;amp;&amp;amp; obj.value&lt;/code&gt;).&lt;/p&gt;

&lt;p&gt;You can often simplify existing checks with the optional chaining pattern:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;obj &amp;amp;&amp;amp; obj.property&lt;/code&gt; becomes &lt;code&gt;obj?.property&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;obj != null &amp;amp;&amp;amp; obj.property&lt;/code&gt; becomes &lt;code&gt;obj?.property&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;obj != null ? obj.property : undefined&lt;/code&gt; becomes &lt;code&gt;obj?.property&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;arr &amp;amp;&amp;amp; arr[i]&lt;/code&gt; becomes &lt;code&gt;arr?.[i]&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;f &amp;amp;&amp;amp; f()&lt;/code&gt; becomes &lt;code&gt;f?.()&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;etc.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;However, there are some cases where refactoring into optional chaining can lead to bugs:&lt;/p&gt;

&lt;h2&gt;
  
  
  Optional chaining short-circuits for nullish values, but not for other falsy values
&lt;/h2&gt;

&lt;p&gt;When &lt;code&gt;a &amp;amp;&amp;amp; a.b&lt;/code&gt; is replaced with &lt;code&gt;a?.b&lt;/code&gt;, the execution for types that can have &lt;a href="https://developer.mozilla.org/en-US/docs/Glossary/Falsy"&gt;falsy&lt;/a&gt; values is changed. This means that the result value and type of the expression can be different with optional chaining.&lt;/p&gt;

&lt;p&gt;The following snippet shows some examples:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;, &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;?.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;undefined&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;       &lt;span class="c1"&gt;// undefined, undefined&lt;/span&gt;
&lt;span class="nx"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;            &lt;span class="c1"&gt;// null, undefined&lt;/span&gt;
&lt;span class="nx"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;            &lt;span class="c1"&gt;// undefined, undefined&lt;/span&gt;
&lt;span class="nx"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;           &lt;span class="c1"&gt;// false, undefined&lt;/span&gt;
&lt;span class="nx"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;               &lt;span class="c1"&gt;// undefined, undefined&lt;/span&gt;
&lt;span class="nx"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;               &lt;span class="c1"&gt;// 0, undefined&lt;/span&gt;
&lt;span class="nx"&gt;test&lt;/span&gt;&lt;span class="p"&gt;({});&lt;/span&gt;              &lt;span class="c1"&gt;// undefined, undefined&lt;/span&gt;
&lt;span class="nx"&gt;test&lt;/span&gt;&lt;span class="p"&gt;([]);&lt;/span&gt;              &lt;span class="c1"&gt;// 0, 0&lt;/span&gt;
&lt;span class="nx"&gt;test&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;length&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;a&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt; &lt;span class="c1"&gt;// a, a&lt;/span&gt;
&lt;span class="nx"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;''&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;              &lt;span class="c1"&gt;// , 0&lt;/span&gt;
&lt;span class="nx"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;NaN&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;             &lt;span class="c1"&gt;// NaN, undefined&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The empty string, which is falsy, but not &lt;a href="https://developer.mozilla.org/en-US/docs/Glossary/Nullish"&gt;nullish&lt;/a&gt;, can be especially problematic. Here is an example were introducing optional chaining can lead to problems:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// without optional chaining&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;s&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// not called for the empty string &lt;/span&gt;
  &lt;span class="c1"&gt;// (e.g., legacy code that works this way)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// with optional chaining&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;s&lt;/span&gt;&lt;span class="p"&gt;?.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// called for the empty string &lt;/span&gt;
  &lt;span class="c1"&gt;// (potentially introducing undesired behavior)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Optional chaining changes the result for null to undefined
&lt;/h2&gt;

&lt;p&gt;When calling &lt;code&gt;a?.b&lt;/code&gt; with null, the result is &lt;code&gt;undefined&lt;/code&gt;. However, with &lt;code&gt;a &amp;amp;&amp;amp; a.b&lt;/code&gt;, the result is &lt;code&gt;null&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Optional chaining can affect the number of calls with side effects
&lt;/h2&gt;

&lt;p&gt;For example, consider changing&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;f&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;f&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;into&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;f&lt;/span&gt;&lt;span class="p"&gt;()?.&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With &lt;code&gt;&amp;amp;&amp;amp;&lt;/code&gt;, &lt;code&gt;f&lt;/code&gt; is called one or two times. However, with optional chaining &lt;code&gt;f&lt;/code&gt; is only called once. If &lt;code&gt;f&lt;/code&gt; has a side effect, this side effect would have been called a different number of times, potentially changing the behavior. This behavior applies not just to function and methods calls but also to getters that can potentially have side effects.&lt;/p&gt;

&lt;h2&gt;
  
  
  TypeScript does not support optional chaining of the 'void' type
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://github.com/microsoft/TypeScript/issues/35850"&gt;TypeScript does not support optional chaining for &lt;code&gt;void&lt;/code&gt;&lt;/a&gt;, event though the corresponding JavaScript code would work.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;Input&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;property&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;f&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;input&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Input&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// this works:&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;input&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;input&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;property&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="c1"&gt;// this breaks because void is not undefined in TypeScript:&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;input&lt;/span&gt;&lt;span class="p"&gt;?.&lt;/span&gt;&lt;span class="nx"&gt;property&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Old browsers and JavaScript engines do not support optional chaining
&lt;/h2&gt;

&lt;p&gt;Optional chaining is an ES2020 feature. It is supported on all modern browsers and Node 14+, but for older browsers and Node versions, transpilation might be required (&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Optional_chaining#browser_compatibility"&gt;compatibility&lt;/a&gt;). &lt;/p&gt;

</description>
      <category>javascript</category>
      <category>typescript</category>
      <category>beginners</category>
      <category>programming</category>
    </item>
    <item>
      <title>JS Refactoring Combo: Simplify Duplicated Function Call Inside If-Else Statement</title>
      <dc:creator>Lars Grammel</dc:creator>
      <pubDate>Fri, 29 Apr 2022 07:08:28 +0000</pubDate>
      <link>https://dev.to/p42/javascript-refactoring-combo-simplify-duplicated-function-call-inside-if-else-statement-21gl</link>
      <guid>https://dev.to/p42/javascript-refactoring-combo-simplify-duplicated-function-call-inside-if-else-statement-21gl</guid>
      <description>&lt;p&gt;If-statements can contain duplicated statements with minimal differences. For example, copy-paste changes can result in such code duplication. The duplication can often be simplified by extracting the difference using the &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Conditional_Operator" rel="noopener noreferrer"&gt;conditional operator&lt;/a&gt; and reducing the if-else to the deduplicated statement.&lt;/p&gt;

&lt;h3&gt;
  
  
  Before (Example)
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;direction&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;left&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;move&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;original&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;move&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;original&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Refactoring Steps
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcbqeiyt14f5k1887qnxg.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcbqeiyt14f5k1887qnxg.gif" alt="Simplify duplicated function call inside if-else statement"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;💡  The refactoring steps are using &lt;a href="https://marketplace.visualstudio.com/items?itemName=p42ai.refactor" rel="noopener noreferrer"&gt;P42 JavaScript Assistant&lt;/a&gt; v1.99&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;a href="https://p42.ai/documentation/code-assist/extract-variable" rel="noopener noreferrer"&gt;Extract variable&lt;/a&gt; twice with the same variable name&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://p42.ai/documentation/code-assist/split-variable-declaration-and-initialization" rel="noopener noreferrer"&gt;Split declaration and initialization&lt;/a&gt; of both extracted constants&lt;/li&gt;
&lt;li&gt;&lt;a href="https://p42.ai/documentation/code-assist/move-first-statement-out-of-if-else" rel="noopener noreferrer"&gt;Move duplicated first statement out of if-else&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://p42.ai/documentation/code-assist/move-last-statement-out-of-if-else" rel="noopener noreferrer"&gt;Move duplicated last statement out of if-else&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://p42.ai/documentation/code-assist/convert-if-else-to-conditional-expression" rel="noopener noreferrer"&gt;Convert the if-else statement into a conditional expression&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://p42.ai/documentation/code-assist/merge-variable-declaration-and-initialization" rel="noopener noreferrer"&gt;Merge variable declaration and initialization&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://p42.ai/documentation/code-assist/inline-variable" rel="noopener noreferrer"&gt;Inline variable&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  After (Example)
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nf"&gt;move&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;original&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;direction&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;left&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>javascript</category>
      <category>beginners</category>
      <category>programming</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
