venus
venusβ€’2y ago

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;
7 Replies
Unknown User
Unknown Userβ€’2y ago
Message Not Public
Sign In & Join Server To View
venus
venusβ€’2y ago
they are in this case, input will be always a number I just wanted to demonstrate two variants that I thought of
Unknown User
Unknown Userβ€’2y ago
Message Not Public
Sign In & Join Server To View
venus
venusβ€’2y 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)
Unknown User
Unknown Userβ€’2y ago
Message Not Public
Sign In & Join Server To View
venus
venusβ€’2y ago
you're right, good point -> value !== 0 ? 1 : 0
reactibot
reactibotβ€’2y ago
This thread hasn’t had any activity in 12 hours, so it’s now locked. Threads are closed automatically after 12 hours. If you have a followup question, you may want to reply to this thread so other members know they're related. https://discord.com/channels/102860784329052160/565213527673929729/1052648404519501884