# Semicolon after object required?

**URL:** <https://forum.codewithmosh.com/t/semicolon-after-object-required/6928>\
**Category:** JavaScript\
**Created:** [August 22, 2021, 12:30am UTC](https://forum.codewithmosh.com/t/semicolon-after-object-required/6928 "2021-08-22T00:30:39Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![gcampton](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/gcampton/32/2164_2.png) [@gcampton](https://forum.codewithmosh.com/u/gcampton)\
**Post date:** [August 22, 2021, 12:30am UTC](https://forum.codewithmosh.com/t/semicolon-after-object-required/6928/1 "2021-08-22T00:30:39Z")

</div>

Hi,  
Moving on to the first exercise in the object section of the JavaScript course I noticed that I didn’t put a semicolon after my object yet the code still executed. Is this required? or was it only required for older versions?

```auto
let address = {
    street: 'Kinabalu Drive',
    city: 'Tamborine Mountain',
    zipCode: 4272
}

function showAddress(address) {
    for (i in address)
        console.log(i, address[i]);
}

showAddress(address);

```

---

<div class="post-metadata">

**Author:** ![eelsholz](https://avatars.discourse-cdn.com/v4/letter/e/439d5e/32.png) [@eelsholz](https://forum.codewithmosh.com/u/eelsholz)\
**Post date:** [August 22, 2021, 1:18am UTC](https://forum.codewithmosh.com/t/semicolon-after-object-required/6928/2 "2021-08-22T01:18:26Z")

</div>

Nope, not required, and neither are your other two semicolons.

Technically, the semicolons are required, but because of a language feature called [automatic semicolon insertion](https://tc39.es/ecma262/#sec-automatic-semicolon-insertion), if you don’t include the semicolons, they’ll be added for you.

---

<div class="post-metadata">

**Author:** ![gcampton](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/gcampton/32/2164_2.png) [@gcampton](https://forum.codewithmosh.com/u/gcampton)\
**Post date:** [August 22, 2021, 2:20am UTC](https://forum.codewithmosh.com/t/semicolon-after-object-required/6928/3 "2021-08-22T02:20:56Z")

</div>

Thanks,  
Also noticed there doesn’t seem to be a need to declare a variable in a for statement and some others.

```auto
for (i in address)

```

does this matter that not ` `for `(let i in address)` ?

---

<div class="post-metadata">

**Author:** ![gcampton](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/gcampton/32/2164_2.png) [@gcampton](https://forum.codewithmosh.com/u/gcampton)\
**Post date:** [August 22, 2021, 2:24am UTC](https://forum.codewithmosh.com/t/semicolon-after-object-required/6928/4 "2021-08-22T02:24:43Z")

</div>

I guess a better question to ask would be if I don’t use standards and insert semicolons and declare variables etc, Then would there be performance issues in large scale programs?

this also works:

```auto
anotherAddress = {
    street: 'Kinabalu',
    city: 'Tamborine',
    zipCode: 000
}

```

---

<div class="post-metadata">

**Author:** ![eelsholz](https://avatars.discourse-cdn.com/v4/letter/e/439d5e/32.png) [@eelsholz](https://forum.codewithmosh.com/u/eelsholz)\
**Post date:** [August 22, 2021, 5:49pm UTC](https://forum.codewithmosh.com/t/semicolon-after-object-required/6928/5 "2021-08-22T17:49:56Z")

</div>

What’s happening with `i` and `anotherAddress` is that they are being added as properties to the `global` or `window` object, which is probably not what you intended! You may want to consider using a linter, such as [eslint](https://eslint.org/docs/user-guide/getting-started), to catch these sorts of things. You can even [configure it to detect missing semicolons](https://eslint.org/docs/rules/semi).

I doubt there is much, if any, noticeable performance implication on relying on automatic semicolon insertion. Some folks actually prefer not using semicolons and use libraries like [standard JS](https://standardjs.com/) to keep their code relatively semicolon free.
