The method execwill receive a string because Boolean operators can return an operand, and not necessarily a Booleanresult, for example:
(&&) , :
true && "foo"; // "foo"
, :
NaN && "anything";
0 && "anything";
(||) , :
false || "bar"; // "bar"
, :
"foo" || "anything"; // "foo"
Falsy: null, undefined, NaN, 0, , , false.
, , ( true).
, :
var test = /(-?)(\d*)n((?:\+|-)?\d*)/.exec(
match[2] === "even" && "2n" || // return '2n' if match[2] is 'even'
match[2] === "odd" && "2n+1" || // return '2n+1' if it 'odd'
!/\D/.test(match[2]) && "0n+" + match[2]|| // return '0n+N' if it a digit(N)
match[2] // otherwise, return the match[2] value
);