Why not just use undefined

  1. Undefined is not a reserved word. It is an attribute of a global object and can be overridden in earlier versions of IE.
    var undefined = 10;
    alert(undefined);
    // undefined -- chrome
    // 10 -- IE 8
Copy the code
  1. In ES5, undefined is just a (read-only) property of a global object and cannot be overridden, but it can be overridden in local scopes;
   (function() { var undefined = 10; alert(undefined); / / 10}) ();Copy the code

Why void 0 instead

MDN definition: The void operator evaluates The given expression and then returns undefined.

Since the void operator evaluates to any expression as undefined, it is perfectly substitutable; It doesn’t matter whether it’s void 0 or void 1;