ternary operator vs logical operator

Benchmark created on


Test runner

Ready to run.

Testing in
TestOps/sec
ternary operator
function myFunc1(isError) {
	return isError ? 1 : 0
}

var val1 = myFunc1(true)
var val2 = myFunc1(false)
ready
logical and
function myFunc2(isError) {
	return (isError && 1) || 0
}

var val3 = myFunc2(true)
var val4 = myFunc2(false)
ready

Revisions

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