# Comparison to multiple values syntactic sugar

**URL:** <https://es.discourse.group/t/comparison-to-multiple-values-syntactic-sugar/357>\
**Category:** 💡 Ideas\
**Created:** [June 9, 2020, 10:33pm UTC](https://es.discourse.group/t/comparison-to-multiple-values-syntactic-sugar/357 "2020-06-09T22:33:10Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jackHedaya](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/jackhedaya/32/341_2.png) [@jackHedaya](https://es.discourse.group/u/jackHedaya)\
**Post date:** [June 9, 2020, 10:33pm UTC](https://es.discourse.group/t/comparison-to-multiple-values-syntactic-sugar/357/1 "2020-06-09T22:33:10Z")

</div>

In ECMA I would use `(variable === val1 || variable === val2 ...)` to attempt to compare a variable to multiple values. I think it would be a lot more elegant to run

`variable === | val1, val 2 |`

and have it automatically expand.

---

<div class="post-metadata">

**Author:** ![zuffik](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/zuffik/32/329_2.png) [@zuffik](https://es.discourse.group/u/zuffik)\
**Post date:** [June 10, 2020, 8:46pm UTC](https://es.discourse.group/t/comparison-to-multiple-values-syntactic-sugar/357/2 "2020-06-10T20:46:44Z")

</div>

I think this can be used as:

```javascript
[val1, val2, ...].includes(variable)

```

---

<div class="post-metadata">

**Author:** ![jackHedaya](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/jackhedaya/32/341_2.png) [@jackHedaya](https://es.discourse.group/u/jackHedaya)\
**Post date:** [June 11, 2020, 2:16am UTC](https://es.discourse.group/t/comparison-to-multiple-values-syntactic-sugar/357/3 "2020-06-11T02:16:55Z")

</div>

Still wouldn’t be able to do operations like \<, \>, etc. with include.

---

<div class="post-metadata">

**Author:** ![JLHwung](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/jlhwung/32/296_2.png) [@JLHwung](https://es.discourse.group/u/JLHwung)\
**Post date:** [June 11, 2020, 2:41am UTC](https://es.discourse.group/t/comparison-to-multiple-values-syntactic-sugar/357/4 "2020-06-11T02:41:09Z")

</div>

I think

```javascript
[val1, val2, ...].some(v => v > variable)

```

is a good alternative.

The proposed `| val1, val2 |` semantics implicitly relies on the context of `| |`. For example, how should they be evaluated?

```javascript
f(| a, b |, c);
g(| a, b |, | c, d |);

```

It is also unclear whether `| a, b |` can be nested

```javascript
val > | a, | b, c | |

```

or whether it can be the RHS of an assignment

```javascript
var x = | 1, 2 |;

```
