ReSharper 2021.1 Help

Code Templates in JavaScript

Most of ReSharper's code template features are also supported in JavaScript. You can find the detailed information on these features in the corresponding topics of the Code Templates section.

Live Templates

Live/Surround templates can be used for generating code in existing files and (if there is the $SELECTION$ parameter in the template body) for surrounding code fragments with template code, such as try...catch statement.
Each live template is identified by a Shortcut — a short string of characters, for example foreach — that you can type right in the editor to invoke the template.

ReSharper provides plenty of predefined live templates. You can also create custom live templates in the dedicated editor or right from existing source code.

Postfix Templates

Postfix templates help you transform expressions that you have already typed without jumping backwards — just type a dot after an expression and pick a template from the completion list.

Below is the list of postfix templates available in JavaScript.

.elseChecks boolean expression to be 'false'if (!expr)
.forofIterates over an iterable objectfor (let x of expr)
.ifChecks boolean expression to be 'true'if (expr)
.notnullChecks expression to be not-nullif (expr !== null)
.notundefinedChecks expression to be not-undefinedif (expr !== undefined)
.nullChecks expression to be nullif (expr === null)
.returnReturns expression from current functionreturn expr;
.undefinedChecks expression to be undefinedif (expr === undefined)
.varIntroduces variable for expressionvar x = expr;
Last modified: 08 March 2021