News for hackers. Stuff that matters.
Re:Minify and Gzip (2022) by djbusby on Monday July 17, 2023 @08:40AM (#36757502)
So, why use two bytes for '!0' when just '1' works?
Re:Minify and Gzip (2022) by tinyhitman on Monday July 17, 2023 @08:44AM (#36757539)
Its not strictly the same. '1' is a number whereas '!0' is a boolean.
Re:Minify and Gzip (2022) by ilyt on Monday July 17, 2023 @12:54PM (#36760657)
I hate that language a bit more now
Re:Minify and Gzip (2022) by hn92726819 on Monday July 17, 2023 @08:45AM (#36757566)
Both 1 and true are truthy, but not the same. That would work if the variable was only ever used in if(x), conditions, etc. Stringifying won't produce the same value either when passing values as well.
Re:Minify and Gzip (2022) by cmg on Monday July 17, 2023 @08:56AM (#36757702)
Because 1 !== true and 0 !== false in JavaScript:

  const index = "Hello HN".indexOf("H")
  console.log(index);
  >> 0
  index == false
  >> TRUE
  index === false
  >> FALSE