0

I have javascript code and I found the following line :

I'm a bit confused about the syntax

e = k.attr("data-icon"), e && (a.icon = e), 

I understand the first part : k.attr("data-icon") but not the rest.

Can any one tell me what does that mean please ?

cheers,

Thomas Carlton
  • 3,503
  • 6
  • 30
  • 60
  • 2
    Do you ask about `,` or `&&` or both? – VLAZ Sep 14 '18 at 14:31
  • I ask for both please :) – Thomas Carlton Sep 14 '18 at 14:32
  • 2
    see [this](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Comma_Operator) – asdf_enel_hak Sep 14 '18 at 14:32
  • 1
    https://stackoverflow.com/questions/3561043/what-does-a-comma-do-in-javascript-expressions and https://stackoverflow.com/questions/41205110/the-logical-and-operators-in-javascript – VLAZ Sep 14 '18 at 14:33
  • comma operator and logical and – epascarello Sep 14 '18 at 14:34
  • 1
    The e && (a.icon = e) means -> if e is truthy, set a.icon to the value of e. And `e` is the value of the previous assignment statement `k.attr('data-icon')`. This should not have been marked as a duplicate. – Steven Spungin Sep 14 '18 at 14:35
  • 3
    This looks very much like minified code, not anything someone has written like that. Do not try to pick up this style. Try finding the un-minified *source* code instead and learn from there what the code is doing. – Bergi Sep 14 '18 at 14:40

0 Answers0