Recently, I've seen this alternate implementation of this
function boolToWord( bool ){
return bool ? "yes" : "no" ;
}
to this
function boolToWord( bool ){
return ['No','Yes'][+bool];
}
May I have some clarification as to what the ['No','Yes'][+bool];
doing? I'm only aware of that having +bool
simply turning the boolean into 0 or 1 depending on the boolean value. But how is it using it as an index to select the value from the previous array ['No', 'Yes']
is this a javascript-only feature? What is this called? Thank you.