The question of lodash.js createSet function

topic description

when looking at the lodash source code, there is such a judgment when you see the createSet function Set & & (1 / setToArray (new Set ([,-0]) [1]) = = INFINITY I don"t quite understand the second half of (1 / setToArray (new Set ([,-0])) [1]) = INFINITY meaning

related codes

const createSet = (Set && (1 / setToArray(new Set([,-0]))[1]) == INFINITY) 
  ? (values) => new Set(values)
  : () => {}
Aug.09,2021

for Set , there is a difference between -0 and + 0 , but the specification specifies that-0 and + 0 are equal after es2015. There is a browser compatibility problem. If the standard is followed, new Set ([,-0]) [1] returns 0 , otherwise it returns -0 , and the result of 1 /-0 is -Infinity does not mean that Infinity, uses empty objects as an alternative implementation of the standard Set at this time,

Menu