Skip to content

Files

Latest commit

 

History

History
40 lines (30 loc) · 747 Bytes

no-void.md

File metadata and controls

40 lines (30 loc) · 747 Bytes

Pattern: Use of void operator

Issue: -

Description

The void operator is primarily used to obtain the undefined value, but this can be done more clearly by using undefined directly. Using void adds unnecessary complexity and can confuse readers unfamiliar with this JavaScript idiom.

Examples

Example of incorrect code:

var undefined = void 0;
function foo() {
  return void 0;
}

const value = void someFunction();
if (value === void 0) {}

void (function() {
  // IIFE
})();

Example of correct code:

var undefined = undefined;
function foo() {
  return undefined;
}

const value = undefined;
if (value === undefined) {}

// For IIFEs, use parentheses
(function() {
  // IIFE
})();