# JS Tip of the Day: The Return of ASI

**URL:** https://forum.kirupa.com/t/js-tip-of-the-day-the-return-of-asi/643158
**Category:** web dev
**Created:** [March 9, 2020, 2:55pm UTC](https://forum.kirupa.com/t/js-tip-of-the-day-the-return-of-asi/643158 "2020-03-09T14:55:31Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![senocular](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/senocular/32/7217_2.png) [@senocular](https://forum.kirupa.com/u/senocular)
#### Post date: [March 9, 2020, 2:55pm UTC](https://forum.kirupa.com/t/js-tip-of-the-day-the-return-of-asi/643158/1 "2020-03-09T14:55:31Z")

</div>

**The Return of ASI**  
Level: Intermediate

Earlier we covered how ASI may not automatically insert semicolons where you might expect them to be. The opposite can also be true, where ASI can insert them when you’d wish it wouldn’t. A good example of this is with the `return` statement.

Any return statement on its own line, without anything following it, will automatically be terminated with a semicolon from ASI.

```javascript
return
// is always seen as
return;

```

Normally, if you’re returning something, this effect wouldn’t come into play because most of the time your return value would come immediately after the `return` keyword. However, if, for example, you’re a fan of the hanging indention style and are returning something like an object literal, you may be inclined to write a return statement such as the following:

```javascript
return
{
    sailor: 'returning home... I hope'
}

```

Unfortunately, this is where ASI will come in and insert a semicolon after `return` causing the object below it to be ignored.

```javascript
return; // due to ASI, returns undefined
{
    sailor: 'are we lost at sea?'
}

```

To correct this, always make sure a return value starts on the same line as `return` itself.

```javascript
return {
    sailor: 'homeward bound!'
}

```

More info:

- [return on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/return)
- [Automatic Semicolon Insertion on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Lexical_grammar#Automatic_semicolon_insertion)
