DEV Community

Cover image for You MUST store this Javascript Operator Index

You MUST store this Javascript Operator Index

Code Oz on November 18, 2021

Here is a list of javascript operator and how to use it! You should mark this and use it when you need to know what is this operator! In order to...
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

Collapse
 
jimmont profile image
Jim Montgomery

Fun article, thanks for it! MDN has some great resources on this topic as well developer.mozilla.org/docs/Web/Jav... developer.mozilla.org/docs/Web/Jav... developer.mozilla.org/docs/Web/Jav...

Collapse
 
yarip28 profile image
Yarip28

Nice sharing! didn't read at all but it seems to be nice!

Collapse
 
codeoz profile image
Code Oz

Thanks Yarip

Collapse
 
qualifymoney profile image
Easy Qualify Money

Perfect work..

Collapse
 
codeoz profile image
Code Oz

thank you a lot

Collapse
 
obaino82 profile image
Obaino82

Perfect work

Collapse
 
codeoz profile image
Code Oz

thanks a lot!

Collapse
 
pengeszikra profile image
Peter Vivo
1 + Math.random() * 6 | 0
Enter fullscreen mode Exit fullscreen mode
Collapse
 
hrrarya profile image
Hridoy Mozumder

Article of the month. Nice.

Collapse
 
codeoz profile image
Code Oz

thank you a lot mate

Collapse
 
karteek_godavarthi profile image
Karteek Godavarthi

Small correction in the code snippet for logical Nullish Coalescing.,
It was mentioned right-handed instead of left-handed.,

Collapse
 
codeoz profile image
Code Oz

thanks it's fixed :D

Collapse
 
codeoz profile image
Code Oz

Very nice feedbacks luke!