The Beauty of Optional Chaining (?.) in TypeScript

The Beauty of Optional Chaining (?.) in TypeScript

Refactoring and reducing the amount of code, while achieving the same thing, is a satisfying feeling. TypeScript gives you ‘Elvis’ to help with that.

The optional chaining operator is supported all popular browsers except IE, Firefox for Andriod, Opera for Android and Samsung Browser.

The Elvis Operator (Optional Chaining)

More shorthand JavaScript notation for cleaner codeJavaScript moves fast and, as a result, TypeScript moves fast with it to push new features and innovations in the way we write JavaScript.All with the aim to increase developer productivity and improve the developer experience.Enter TypeScript 3.7…TypeScript 3.7 gave us the optional chaining operator ( ?. ) that has the ability to shrink our, otherwise long and complex, code. The refactoring possibilities with this operator become obvious as soon as you start to use it.Having learned Swift, it was always a feature that I thought was missing in TypeScript.I would always start to write it, realize I was thinking in the wrong language, then wonder why it’s not part of JavaScript **while beginning to write the more daunting version containing multiple && , !== and ? ‘s.The reason I was subconsciously writing optional chainingwas that it just spoke common sense to me. **Having to write the alternative in TypeScript used to be verbose, time-consuming, and repetitive. That was until it was finally implemented. I have never looked back.

What’s great about TypeScript, is that you always get to use the latest features, because you just transpile to standard JavaScript in the end anyway.

What’s the logic behind it?

When using dot (.) notation to access properties/methods, instead of causing an error if a reference (the object) is nullish (null or undefined), the expression short-circuits, returning undefined.

programming web-development javascript software-engineering typescript

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Offshore Software Development - Best Practices

To make the most out of the benefits of offshore software development, you should understand the crucial factors that affect offshore development.

Software Developer vs Software Engineer — Differences: Bogus or Real?

In this article, see if there are any differences between software developers and software engineers. What you’re about to read mostly revolves around my personal thoughts, deductions, and offbeat imagination. If you have different sentiments, add them in the comment section, and let’s dispute! So, today’s topic…

Software Developer vs Web Developer | Difference Web Developer & Software Developer

Software Developer vs Web Developer | Difference Web Developer & Software Developer | Software development and web development are normally used interchangeably. Although both include development, a software developer has different responsibilities from that of a web developer.

5 Core Criteria for Selecting Software Development Company -

Check out these five criteria for the selection of your software vendor, and you will never regret having the wrong quality product made for you.

Developer Career Path: To Become a Team Lead or Stay a Developer?

For a developer, becoming a team leader can be a trap or open up opportunities for creating software. Two years ago, when I was a developer, ... by Oleg Sklyarov, Fullstack Developer at Skyeng company