venus – 18-08 Dec 14

can I make this condition even shorter?
const value = 2;
const v1 = value === 0 ? 0 : 1;
const v2 = !value ? 0 : 1;
const value = 2;
const v1 = value === 0 ? 0 : 1;
const v2 = !value ? 0 : 1;
UU
Unknown User491d ago
V
venus491d ago
they are in this case, input will be always a number I just wanted to demonstrate two variants that I thought of
UU
Unknown User491d ago
V
venus491d ago
good to know, thanks 🙂 so this should be the correct way to write it, right? const v3 = value > 0 ? 1 : 0; or Number(value > 0)
UU
Unknown User491d ago
V
venus491d ago
you're right, good point -> value !== 0 ? 1 : 0
UU
Unknown User490d ago