I am trying upgrade my javascript programming skills ( or lets say my programming skills period : ) )
so I am trying to understand some semantics :
in the first line what does the "?" mean as well as the minus sign in "-distance"
in the second line what does '+=' or '-=" mean?
el.css(ref, motion == 'pos' ? -distance : distance)
animation[ref] = (mode == 'show' ? (motion == 'pos' ? '+=' : '-=') : (motion == 'pos' ? '-=' : '+=')) + distance;
thank you
a ? b : c
means "b
if a
is true, c
otherwise".
-a
means a
, negated.
a -= b
and a += b
mean a = a - b
and a = a + b
respectively. However, in your example these operators aren't actually present in the code, they are just text strings the code is manipulating.
? is the ternary operator
it equals
if( motion == 'pos' ) { return -distance; } else { return distance; } // - is just negating the distance value
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With