1 of 12

Optional Chaining

2 of 12

Hey!

I am Dustin Savery

Senior Developer at GoDaddy

You can find me at @dustinsavery

2

3 of 12

And it’s not just me, this proposal has had nearly

2500

unique views in the last 2 weeks alone!

3

4 of 12

You ever wonder why we’re here?

Very brief refresher of Optional Chaining

4

5 of 12

Simply put, Optional Chaining is syntactic sugar for finding a value in a tree-like structure

5

6 of 12

But… why?

  • Simplify code writing
  • Help with code clarity and readability
  • Deliver predictable results

6

7 of 12

What is optional chaining?

const a = { b: { c: 42 }};

// With Optional Chaining

a?.b?.c

// Without Optional Chaining

a == null ? undefined : a.b == null ? undefined : a.b.c

7

8 of 12

What Optional Chaining is NOT

  • Error Prevention
  • Logic Alteration/Augmentation

8

9 of 12

What does this proposal support?

  • Property Access

const a = { b: 42 };

// Static Property Access

const x = a?.b;

// Dynamic Property Access

const y = a?.[‘b’];

9

10 of 12

What does this proposal NOT support?

  • Optional Function Execution
  • Optional Deletion
  • Optional Construction
  • Optional Template Literal
  • Optional Property Assignment

10

11 of 12

It hasn’t been without controversy

11

12 of 12

So where do we go from here?

12