0

I have a object:

child_el = {
          height: sub_height,
          top: sizes.top,
          color: if sizes.top == 1 ? 0 : 1,
          };

How I can correctly put condition in property color?

Jadasdas
  • 869
  • 4
  • 19
  • 39

2 Answers2

3

You just need to remove the if from color property.

Check the below code :

child_el = {
   height: sub_height,
   top: sizes.top,
   color: sizes.top === 1 ? 0 : 1
};

Reference : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Conditional_Operator

Ravi Sachaniya
  • 1,641
  • 18
  • 20
  • 1
    == operator can create problems in this case, have a look here https://stackoverflow.com/questions/523643/difference-between-and-in-javascript – LellisMoon Apr 20 '18 at 07:14
2
child_el = {
   height: sub_height,
   top: sizes.top,
   color: sizes.top === 1 ? 0 : 1,
};
LellisMoon
  • 4,810
  • 2
  • 12
  • 24