Skip to content

Files

Latest commit

 

History

History
39 lines (29 loc) · 840 Bytes

no-restricted-globals.md

File metadata and controls

39 lines (29 loc) · 840 Bytes

Pattern: Use of restricted global variable

Issue: -

Description

Some global variables should be avoided either because they're deprecated (like the global event object), environment-specific, or conflict with better alternatives. Using these globals can lead to maintainability issues or bugs.

Examples

Example of incorrect code:

function handleClick() {
  console.log(event);  // Using global event object
}

if (isFinite(value)) {  // Using global isFinite
  process(value);
}

if (isNaN(x)) {  // Using global isNaN
  handleInvalid();
}

Example of correct code:

function handleClick(event) {  // Use event parameter
  console.log(event);
}

if (Number.isFinite(value)) {  // Use Number method
  process(value);
}

if (Number.isNaN(x)) {  // Use Number method
  handleInvalid();
}