Learn 11 JavaScript and TypeScript shorthands to write more concise, efficient, and readable code. This article covers shorthands for declaring variables, assigning values, performing comparisons, writing conditional statements, and working with arrays, objects, and functions.

There is a very fine line between writing clean and efficient code and writing code that only you can read. And the worst part is, that line is not universal, some people would draw it much further than others so when it comes to deciding if a piece of code is legible enough for everyone we tend to stay away from using many shorthands such as ternary operators, on-line arrow functions and whatnot.

But the ugly truth is: sometimes, those shorthands come in very handy and are easy enough that anyone who’s interested enough in reading our code can and will understand them.

So in this article, I want to cover some very useful (and sometimes cryptic) shorthands that you can find both in JavaScript and in TypeScript so you can either use them yourself or at least, have know them in case the person who’s code you’re reading has used them.

  1. The Nullish Coalescing Operator
  2. Logical nullish assignment
  3. TypeScript’s constructor shorthand
  4. The ternary operator
  5. Take advantage of OR’s lazy evaluation
  6. The double bitwise NOT operator
  7. Object property assignment
  8. Implicit return from arrow functions
  9. Default function parameters
  10. Casting any value to a boolean with !!
  11. Destructuring and spread operators

#javascript #typescript #web-development

11 JavaScript and TypeScript Shorthands You Should Know
3.15 GEEK