Rhys
Rhys2y ago

✅ – Rhys – 02-32 Oct 5

Not really sure how to google this one, is there a shorthand for ternary operators when you write something like
const x = obj.val ? obj.val : 70
const x = obj.val ? obj.val : 70
Writing obj.val there twice feels redundant
7 Replies
rubberduckies
rubberduckies2y ago
const x = obj.val || 70 just be careful because if obj.val is zero, it will give you 70, in both ways
Rhys
Rhys2y ago
thank you! good call out on the javascript doing that also that's helpful to remember
reactibot
reactibot2y ago
This question has an answer! Thank you for helping 😄 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/1027045666515587193
devTej🧑💻
you can use thi obj.val ?? 70
devTej🧑💻
Nullish coalescing operator (??) - JavaScript | MDN
The nullish coalescing operator (??) is a logical operator that returns its right-hand side operand when its left-hand side operand is null or undefined, and otherwise returns its left-hand side operand.
devTej🧑💻
If the left hand is still 0 still it works
reactibot
reactibot2y 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/1027045666515587193