✅ – 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
Writing obj.val there twice feels redundant
7 Replies
const x = obj.val || 70
just be careful because if obj.val is zero, it will give you 70, in both waysthank you! good call out on the javascript doing that also that's helpful to remember
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
you can use thi obj.val ?? 70
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.
If the left hand is still 0 still it works
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