Frontend Development 9 min read

The Dark Side of JavaScript: Three Features You Should Avoid Using

JavaScript, despite its evolution and flexibility, still retains three outdated features—void operator, with statement, and labels—that remain functional but are inefficient or confusing, and developers are advised to avoid using them in modern code to maintain readability and prevent bugs.

Rare Earth Juejin Tech Community
Rare Earth Juejin Tech Community
Rare Earth Juejin Tech Community
The Dark Side of JavaScript: Three Features You Should Avoid Using

JavaScript has been around for about 26 years, evolving significantly thanks to community input, but some legacy features remain that are either unnecessary or inefficient.

Void operator : Historically used in links like href="javascript:void(0)" to suppress navigation. It returns undefined for any expression, a role now largely superseded by the undefined keyword itself. Modern use cases are limited to forcing a function to return undefined , such as in single‑line arrow functions where you want to discard the result.

(function (window, undefined) {

})(window, void(0))
const double = x => x * 2;
const callAfunction = () => void myFunction();

Using void in this way provides little benefit and is generally discouraged.

With statement : Allows extending the scope chain of a statement, but it is discouraged by MDN because it leads to confusing code. Example:

function greet(user) {
  with(user) {
    console.log(`Hello there ${name}, how are you and your ${kids.length} kids today?`)
  }
}

greet({ name: "Fernando", kids: ["Brian", "Andrew"] })

Mixing object properties with function parameters via with can produce unexpected results and makes the code harder to understand, so it should be avoided.

Labels : JavaScript implements label statements that can be targeted by break or continue . While they resemble goto in other languages, they are rarely needed and can make control flow opaque.

label1: {
  console.log(1)
  let condition = true
  if(condition) {
    break label1
  }
  console.log(2)
}
console.log("end")

When combined with loops, labels can produce complex flow:

let i, j;
loop1:
for(i = 0; i < 10; i++) {
  loop2:
  for(j = 0; j < 10; j++) {
    if(j == 3 && i == 2) {
      continue loop2;
    }
    console.log({i, j})
    if(j % 2 == 0) {
      continue loop1;
    }
  }
}

Such constructs are hard for humans to read and maintain, so they should be avoided in favor of clearer structures.

In conclusion, while the author appreciates JavaScript’s growth, the void operator, with statement, and label usage are legacy features that modern codebases should steer clear of to keep code clean, maintainable, and less error‑prone.

JavaScriptBest Practiceswith-statementLabelsvoid operator
Rare Earth Juejin Tech Community
Written by

Rare Earth Juejin Tech Community

Juejin, a tech community that helps developers grow.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.