Below you will find pages that utilize the taxonomy term “Programming”
Postsread more
My Favorite Little Operator
Sometimes, there are little things that solve so much that we take for granted. There’s also things that solve so much that aren’t used as often.
Recently, I’ve been relying on ??, which is a very interesting operator called “null-coalescing operator”. A fairly seasoned programmer probably uses it very often and wouldn’t find this as fascinating as I did, but for me, it’s a game-changer.
Take this for instance:
const somevar = null;
if (somevar === null) {
console.log("non-null value");
} else {
console.log(somevar);
}
Here, we print out somevar
, and if it’s null, we print a string. You
can also use a ternary operator to clean it up and rewrite it like
this.