R
Reactiflux

help-js

✅ – Rhys – 02-32 Oct 5

RRhys10/5/2022
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
Rrubberduckies10/5/2022
const x = obj.val || 70 just be careful because if obj.val is zero, it will give you 70, in both ways
RRhys10/5/2022
thank you! good call out on the javascript doing that also that's helpful to remember
UUUnknown User10/5/2022
2 Messages Not Public
Sign In & Join Server To View
DdevTej🧑💻10/5/2022
you can use thi obj.val ?? 70 https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Nullish_coalescing_operator If the left hand is still 0 still it works
UUUnknown User10/5/2022
Message Not Public
Sign In & Join Server To View

Looking for more? Join the community!