educative.io

Mistake in discerning rest and spread operators?

Usually, the rest operator happens on the right side of an assignment, with the spread operator on the left.

Isn’t this the other way around?

@Christian_Beiwinkel

Both rest and spread operators have the same syntax i.e. ...object . They only differ in their functionality. Three dots appears on left side both for rest and spread operators.

The question wasn’t really about which side of the variable name they appear (because you’re right, it’s left for both spread and rest operators), but rather about the side of an assignment. For example:

const a = [1, 2, 3]

b = [...a, 4]

Here, I’m using the spread operator on the right side of an assignment.

const [a, ...b] = [1, 2, 3]

Here, I’m using the rest operator on the left side of an assignment. The phrase as found in the lesson suggested though that rest operators typically appears on the right side of assignments, and spread operators on the left, which I believe is not the case.