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?

0

2 Answers 2

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

Sign up to request clarification or add additional context in comments.

1 Comment

== operator can create problems in this case, have a look here stackoverflow.com/questions/523643/…
2
child_el = {
   height: sub_height,
   top: sizes.top,
   color: sizes.top === 1 ? 0 : 1,
};

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.