Hacker News new | ask | show | jobs
by ufo 1999 days ago
Actually, I think that might work in Javascript! All the numbers are IEE754 floating point numbers and there are separate values for positive and negative zero.
1 comments

iirc using numeric literal values there's a coercion step—a console example:

  let arr = new Array(10);
  // 1e1 => 10
  arr[1e1] = 1;
  console.log(`arr[10]  === 1 => ${arr[10]  === 1}`)
  console.log(`arr[1e1] === 1 => ${arr[1e1] === 1}`)

So -0 becomes 0:

  arr[0] = 2;
  console.log(`arr[0]   === 2 => ${arr[0]  === 2}`);
  console.log(`arr[-0]  === 2 => ${arr[-0] === 2}`);
  arr[-0] = 3;
  console.log(`arr[0]   === 3 => ${arr[0]  === 3}`);
  console.log(`arr[-0]  === 3 => ${arr[-0] === 3}`);