• 0 Posts
  • 18 Comments
Joined 11 months ago
cake
Cake day: December 22nd, 2023

help-circle

  • My top 3 (as mainly JS dev) would be:

    1. Number overflow. It happens when you’re backend send big number ID serialized in a JSON. The solution is to wrap the number into a string when you know that can happens.
    JSON.parse('{"n": 123456789123456789012.0}').n
    // => 123456789123456800000
    
    1. Mutating an Object by ref (now I use Object.freeze a lot). Something like:
    const CONFIGURATION = { conf: { enabled: false } }
    // setup a "copy"
    let currentConfiguration = { ...CONFIGURATION }
    currentConfiguration.conf.enabled  = true
    // try to reset the conf
    currentConfiguration = { ...CONFIGURATION }
    // => { conf: { enabled: true } }
    
    1. Assignation instead of comparison (now my IDE warn me)
    if (foo = false) {
      // do something
    }
    














  • For example, all of the list abstractions (map, filter, reduce, etc.) will copy the array to a new list every time you chain them.

    This methods were added to generator recently. So you can avoid copying the array in memory.

    All this is also without even getting started on the million JS frameworks and libraries which make it really easy to have vendor lock-in and version lock-in at the same time

    In my opinion, it’s also what make JS good. There a package for almost everything.