Now that might sound great but it turns out that Automatic Semicolon Insertion can cause some interesting issues
However if we would return an object literal and format our code the same way we would run into a problem. Consider the following code:
You might expect this to print an object with a property sum containing the value 3. However the code prints “undefined”. Compare that with the following code that is only formatted differently:
This will print the expected object with a sum of 3.
This unexpected behavior is caused by semicolon insertion. instead of the code you most likely think will execute the following executes:
Notice the semicolon after the return statement?
That actually means return nothing, i.e. undefined, and just have some unreachable code on the next few lines. That is completely valid so that is what happens
Unfortunately ‘use strict’ doesn’t help here either. It will prevent some errors but it doesn’t make semicolons required