DEV Community

Discussion on: You MUST store this Javascript Operator Index

Collapse
 
seanmay profile image
Sean May • Edited

A couple of thoughts, one technical and one subjective:

  1. the ... on the left-hand-side of an assignment statement is also a "rest" operator. "spread" is for expressions (or rhs in statements). When you are putting a bunch of stuff into something, it's a "spread". When you are pulling a bundle of stuff out of something, and giving that bundle a new name, it's a "rest". In functions you are pulling the bundle out of the arguments array
    const f = (x, y, z, ...extraDimensions /*rest of the args*/) => {};
    const [x, y, z, ...extraDimensions /*rest of the array*/] = dimensions;
    const { x, y, z, ...extraDimensions /*rest of the object*/} = dimensions;

  2. I personally feel you should be using ?? at least as often as you are using ?., if not more often. Again, this is the subjective opinion. If you are often using ?. that means you are often getting undefined. If you are passing undefined around, it means that you are often forcing other people (or other parts of the codebase) to do null checking. If you are handling those missing holes in your data with ??, then you have fewer reasons to use ?. farther down the line... Null checking is Sir Tony Hoare's "Billion-Dollar Mistake" and is generally better handled on the outskirts of a system, near the I/O, rather than in the middle of all of the logic... the opinion might be subjective, but it's got a pretty sound backing, by even the inventor of Null (or the person who introduced the concept to programming languages), let alone language researchers.

Collapse
 
codeoz profile image
Code Oz

thanks for replied! I changed a few things for ... operator