# Operator dilemma!!

**URL:** <https://es.discourse.group/t/operator-dilemma/795>\
**Category:** I have questions\
**Created:** [May 18, 2021, 3:25pm UTC](https://es.discourse.group/t/operator-dilemma/795 "2021-05-18T15:25:51Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jithujoshyjy](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/jithujoshyjy/32/399_2.png) [@jithujoshyjy](https://es.discourse.group/u/jithujoshyjy)\
**Post date:** [May 18, 2021, 3:25pm UTC](https://es.discourse.group/t/operator-dilemma/795/1 "2021-05-18T15:25:51Z")

</div>

```javascript
console.log(+(1, 2, 3, 4))
// returns undefined
// expected 10😩

```

1. why is this valid?
2. why is the result undefined?
3. what's happening here?

---

<div class="post-metadata">

**Author:** ![ljharb](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/ljharb/32/8_2.png) [@ljharb](https://es.discourse.group/u/ljharb)\
**Post date:** [May 18, 2021, 3:41pm UTC](https://es.discourse.group/t/operator-dilemma/795/2 "2021-05-18T15:41:51Z")

</div>

`1, 2, 3, 4` is the comma operator - it evaluates to 4, and `+4` also evaluates to `4`.

`console.log()` itself always returns `undefined`, it just prints its argument to the console (4, in this case).

If you want to get 10 from 1, 2, 3, and 4, you can do `[1, 2, 3, 4].reduce((a, b) => a + b)`, for example.

---

<div class="post-metadata">

**Author:** ![theScottyJam](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/thescottyjam/32/616_2.png) [@theScottyJam](https://es.discourse.group/u/theScottyJam)\
**Post date:** [May 18, 2021, 4:01pm UTC](https://es.discourse.group/t/operator-dilemma/795/3 "2021-05-18T16:01:02Z")

</div>

See [this MDN article](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Comma_Operator) on the comma operator.

---

<div class="post-metadata">

**Author:** ![jithujoshyjy](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/jithujoshyjy/32/399_2.png) [@jithujoshyjy](https://es.discourse.group/u/jithujoshyjy)\
**Post date:** [May 18, 2021, 4:29pm UTC](https://es.discourse.group/t/operator-dilemma/795/4 "2021-05-18T16:29:25Z")

</div>

super weird behaviour!
