'error "Invalid parenthesized assignment pattern" background info
In my React project, I got this error:
SyntaxError: ... Invalid parenthesized assignment pattern
const add = (a, b) = { return a + b; };
^
I do understand the error, but I am surprised that I could not find any information about it.
- Where does it come from ?
- Where is it documented ?
What I want to understand
I do understand the problem here (the '>' is missing in this arrow function), but I wonder (1) where this error comes from exactly (not the Browser?), and (2) where could I find information about it.
The error message obviously interprets this as a wrong assignment, not as a wrong arrow function:
const add = (a, b) = { return a + b; };
// error ----^
// actually wrong --^
Where it obviously does not come from:
If I write the same statement in the NodeJs CLI, I get:
const add = (a,b) = { return ''; }
^^^^^
ReferenceError: Invalid left-hand side in assignment
in the Firefox console:
SyntaxError: invalid assignment left-hand side
Note that I am using Firefox for development, but the error message during development is different than the error message when I try the same in the Firefox console (Invalid parenthesized assignment pattern vs. SyntaxError: invalid assignment left-hand side)
Solution 1:[1]
Since you are using the ES6 arrow function, you have to define =>
const add = (a, b) = { return a + b; }; // here you missed arrow for function **=>**
const add = (a, b) **=>** { return a + b; }; //modified by adding **=>**
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Simas Joneliunas |
