JavaScript has a feature where it automatically adds semicolons to end statements when necessary. For example:
return
{
major: this.valA,
minor: this.valB
}
In this case, the return statement is executed as if you had written return;
. However, if you write:
return {
major: this.valA,
minor: this.valB
}
the entire object will be returned with a semicolon added after the object.
The rules for automatic insertion of semicolons in JavaScript are as follows (source):
- when the next line starts with code that breaks the current one (code can span multiple lines)
- when the next line starts with a
}
, closing the current block
- when the end of the source code file is reached
- when there is a
return
statement on its own line
- when there is a
break
statement on its own line
- when there is a
throw
statement on its own line
- when there is a
continue
statement on its own line