Proper use of syntax, specifically semicolon in javascript


This is a solution to one of the exercises:

const lifePhase = age => {
if (age < 0 || age > 140) {
return ‘This is not a valid age’
} else if (age < 4) {
return ‘baby’
} else if (age < 13) {
return ‘child’
} else if (age < 20) {
return ‘teen’
} else if (age < 65) {
return ‘adult’
} else {
return ‘senior citizen’
Here’s a link to the exercise.

My question. There are no semicolons ending lines. Should there be a semicolon right before a curly bracket (e.g. … return baby; } … ? Also, since this is a function expression, should there be a semicolon after the last curly bracket?

Thank you.


semi-colons are part of some statements, whether that’s the case for a particular statement is something you can find out by looking up the syntax for that statement, for example on mdn

Javascript has some “helpful” features, one of them is to make semi-colons automatically inserted if missing. This doesn’t say anything about whether it’s better to include them or omit them, but it’s a terrible choice to make them optional.


On that we may both agree. It might have been simpler for people to learn the correct usage if they were faced with syntax errors at every turn.