What is the correct fix?
enum Role { User, Admin }
function isAdmin(r: Role) {
return r == Role.Admin || r;
}
- Return
r === Role.Adminon its own - Return
r !== Role.Adminon its own - Change the enum so
Userstarts at 1 - Compare against the string
'Admin'
The trailing
Play Problem Solving ▸
|| r makes any non-zero role truthy; the comparison alone is the answer.