BTW the code does not completely replicate the ternary operator (at least how it gets evaluated in most languages).
<predicate> ? <consequent> : <alternative>
in most languages if the predicate
is an expression that evaluates to true
then only the <consequent>
gets evaluated and the <alternative>
if the <predicate>
is set to false
then only the <alternative>
expression gets evaluated
open up your JS console and type
false ? console.log("never printed") : console.log("LOGGED!")
You’ll get LOGGED
in the console, in the main
function above both a
and a-1
are evaluated regardless of the result of a > b
.