Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

ui: Simplify code #4956

Copy link
Copy link
@davidjumani

Description

@davidjumani
Issue body actions

Optional chaining

The optional chaining ?. is a safe way to access nested object properties, even if an intermediate property doesn’t exist.
(error.response && error.response.headers && error.response.headers['x-description']) || error.message
using optional chaining it reduces to
error.response?.headers?.['x-description'] || error.message

Ref : https://javascript.info/optional-chaining

This can also be used to invoke methods on objects, etc
This improves readability as well as simplifies the existing code

Nullish coalescing

Nullish coalescing is an improvement on the || operator where it only checks if an object is null or undefined.
Using the || operator returns false if the object is zero or an empty string which can cause issues in the code when the value is zero but incorrectly treated as false

let height = 0;

alert(height || 100); // 100
alert(height ?? 100); // 0

Ref: https://javascript.info/nullish-coalescing-operator

Object shorthand

Provides a simpler way when creating an object who's keys have the same name as the variables passed-in as properties

let cat = 'Miaow';
let dog = 'Woof';
let bird = 'Peet peet';

let someObject = {
  cat,
  dog,
  bird
}

Ref https://alligator.io/js/object-property-shorthand-es6/

ISSUE TYPE
  • Enhancement Request
Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.