DEV Community


Discussion on: PHP 8 features I wish also existed in JavaScript

jfbrennan profile image
Jordan Brennan • Edited

Optional chaining in JavaScript has been supported by all browsers and Node for close to a year now.

Its use in source has also been possible via Babel for a few years.

Match does look cool, but for these cases I usually get away with a simple object literal:

const weights = {
  100: 'Super Thin',
  300: 'Thin',
  400: 'Normal',
  600: 'Bold',
  900: 'Heavy'

const fontWeight = weights[weight]
Enter fullscreen mode Exit fullscreen mode

Edit: ah, somebody already mentioned this. Their immediate lookup is better too