Spare a few moments and take a glance at this seemingly innocent block of code:

var getCharacter = function () {
  return
  {
    id: 50,
    name: 'Leela',
    show: 'Futurama'
  }
};

This simple function will throw an error as soon as the JavaScript engine tries to parse it:

Uncaught SyntaxError: Unexpected token :

This is due to automatic semi-colon insertion (ASI); when semicolons are inserted automatically, by the JavaScript engine, after it encounters a statement mentioned in a list defined in ECMA-262 5.1 § 7.9

The following statements will trigger ASI: * do * while * continue * break * return * throw * var

Looking back to our original function, notice how the first brace and the return statement itself are in different lines. Due to ASI, JavaScript will automatically insert a semicolon after the return statement. Therefore, what JavaScript actually sees is:

var getCharacter = function () {
  return;
  {
    id: 50,
    name: 'Leela',
    show: 'Futurama'
  }
};

Now that the return statement is terminated with a semicolon, the original object that was meant to be returned is orphaned:

{
  id: 50,
  name: 'Leela',
  show: 'Futurama'
}

To you, this still looks like a normal JavaScript object. However, since it is simply floating in the vastness of space, the grammar it uses is invalid—specifically the comma at the end of id: 50,.

All by itself, { id: 50, name: 'Leela' } is invalid JavaScript. Technically, you could swap the comma with a semicolon and it will pass the ECMA5 grammar rules: { id: 50; name: 'Leela' }.

The moral of the story? Get your opening brace and return statement on the same line if you need to return an object literal:

var getCharacter = function () {
  return {
    id: 50,
    name: 'Leela',
    show: 'Futurama'
  };
};