Optional Chaining vs. Non-optional Chaining

Benchmark created on


Description

Optional chaining performance vs. && operators at every level

Test runner

Ready to run.

Testing in
TestOps/sec
Using Optional Chaining
let array = [({
	myObject: {
		myOtherObject: {
			myValue: -1
		}
	}
})];

if(array?.[0]?.myObject?.myOtherObject?.myValue === -1) {
console.log("YAY");	
}
ready
&& Operators at Each Level
let array = [({
	myObject: {
		myOtherObject: {
			myValue: -1
		}
	}
})];

if(array.length && array[0] && array[0].myObject && array[0].myObject.myOtherObject && array[0].myObject.myOtherObject.myValue === -1) {
	console.log("YAY")
}
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.