Arrow function

In this exercise why does adding a semicolon to the implicit return function results in an error

const secretMessage => animal[0];) //SyntaxError: missing ) after argument list

but doing this

const secretMessage => {return animal[0];})

works just fine

1 Like

That’s an excellent question. A concise body arrow function is only allowed a single statement. That statement is a return statement. While it may appear that you only have a single statement, you actually have 2.

See empty - JavaScript | MDN


Interesting. So what you are saying is an empty statement is still a statement. That is wild.
Does this imply that every time a semicolon is used you inadvertently create an extra statement?

Well, I suppose if you intentionally typed the semicolon it wouldn’t be inadvertent. The rules, style guides, etc. still apply as to when semicolons must or should be used, but they are statements by definition.

1 Like