✅ – 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
R
rubberduckies562d ago
const x = obj.val || 70 just be careful because if obj.val is zero, it will give you 70, in both ways
R
Rhys562d ago
thank you! good call out on the javascript doing that also that's helpful to remember
UU
Unknown User562d ago
D
devTej🧑💻561d ago
you can use thi obj.val ?? 70
D
devTej🧑💻561d ago
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.
D
devTej🧑💻561d ago
If the left hand is still 0 still it works
UU
Unknown User561d ago