Error due to semicolon added to return statement of Arrow function expression

Asked 2 years ago, Updated 2 years ago, 262 views

ar.map() did not display Array [2,3,4] if the inside of ( ) is an Arrow function expression and there is a semicolon in the return statement. Can you point out the cause or error of this problem?

 function f1(x) {return x+1;}
constar = [1,2,3];
console.log(ar.map(/*...*/));

javascript

2022-09-30 21:58

1 Answers

One form of the Arrow function expression as an argument for map

param=>expression

; is unnecessary if you use the , and the expression does not contain ;.

; constitutes a statement.
For example,

 expression;

is a statement.

Sentences originally require ;, but JavaScript's semicolon auto-insert feature allows many syntaxes to omit the statement ;.So, sentence without semicolon

return expression

is no longer an error.


2022-09-30 21:58

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.