Prefer to replace some of typeof obj !== 'undefined' with optional chaining possibly

Created on 14 November 2024, about 1 month ago

Problem/Motivation

Some of JavaScript checks object existence with typeof obj !== 'undefined' and checks property existence in the object. For example, it checks drupalTranslations and its property exsitence with below code in the /misc/drupal.js.

if (
  typeof drupalTranslations !== 'undefined' &&
  drupalTranslations.strings &&
  drupalTranslations.strings[options.context] &&
  drupalTranslations.strings[options.context][str]
)

This code is redundant for current JavaScript because using optional chaining operator can makes code more shorter like below.

if (drupalTranslations?.strings?.[options.context]?.[str])

Proposed resolution

Use optional chaining operator.

Remaining tasks

User interface changes

No.

API changes

No.

Data model changes

No.

Release notes snippet

πŸ“Œ Task
Status

Active

Version

11.0 πŸ”₯

Component

javascript

Created by

πŸ‡―πŸ‡΅Japan tom konda Kanagawa, Japan

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024