Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

105
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!