DEV Community

Discussion on: 😰 Optional chaining trap !

Collapse
 
smeijer profile image
Stephan Meijer

I took some time to create that peformance test you're talking about. But no, it doesn't perform better. Mostly, because it will check way more then required.

We as developers know that if user is not an object, that it doesn't meet our requirements. Babel will however check against null and void 0. While we could just check if it's "truthy". So the transpiled code contains at least twice as much checks as required.

I just published a small post, inspired by this one. If you're only interested in the performance, you can check the outcome here: jsperf.com/costs-of-optional-chaining.

Collapse
 
stereobooster profile image
stereobooster

I meant performance of babel-compiled optional chaining vs baseGet. What author talked about in the post