Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

106
Vistas
Comma operator with IIFEs

Inside of the react-redux library, in the file defining useSelector, I have found multiple instances of comma operators used with IIFEs in the follow manner:

    var _useReducer = (0, _react.useReducer)(function (s) {
    return s + 1;
  }, 0),
      forceRender = _useReducer[1];
      
  var subscription = (0, _react.useMemo)(function () {
    return (0, _Subscription.createSubscription)(store, contextSub);
  }, [store, contextSub]);
  var latestSubscriptionCallbackError = (0, _react.useRef)();
  var latestSelector = (0, _react.useRef)();
  var latestStoreState = (0, _react.useRef)();
  var latestSelectedState = (0, _react.useRef)();

I can't understand or find any reference as to why they are using 0 inside of the IIFEs.

In the context of the comma operator, each value is evaluated and only the last expression is assigned to the variable.

In my eyes and to my understanding, the 0s are meaningless. Can someone explain them?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

The reason it does this is that calling a function from a comma operator puts the called function in the global context. (0, function)() the zero is just a convention.

If it was not called using this method this (the context) would be the local scope. You often find this behavior in transpiled code such as babel or TypeScript.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda