Are Semicolons Necessary in JavaScript?

Kyle Robinson Young · 68K views · 2015 · 7:44

Open on YouTube

Web developmentPython, Ruby & scripting languagesexplainer

Why Stack Overflow recommends it

Stack Overflow users link it in comments and answers when explaining automatic semicolon insertion or defending a no-semicolon style, especially for beginners.

Recommended by 2 people across 3 different months, 2016 to 2026.

What it is

A short 2015 JavaScript explainer by Kyle Robinson Young on whether semicolons are needed, covering how automatic semicolon insertion works and why omitting them can cause bugs. He also explains why he chooses to teach JavaScript without semicolons.

What people said

Recommends Michael Schwartz · 2016-03 · Stack Overflow · on “On jquery is programmatically correct get an attribute after removed the element”

Correct me if I maybe mistaken. From what I understand you're asking what's the difference between this approach... var rel = $(this).closest("tr").remove().attr("rel"); vs this approach? var $deltr = $(this).closest("tr").remove(); // code using $deltr to store it var rel = $deltr.attr("rel"); The difference between the two depends on who's coding. The point of the variables is a lot of times it's easier to store a larger string, method function, etc: instead of calling it multiple times. In addition you may watch to look into ASI (Automatic Semicolon Insertion) [LINK] (If you don't want to read you can watch this video [this video] instead) The only difference between the two depends on how a u

Recommends Qwerty · 2023-12 · Stack Overflow · on “Waiting for more than one concurrent await operation”

@knittl I am anti-semicolonist and I only use them explicitly when the statement I am ***currently writing*** could interfere with a previous statement, such as `console.log('WAITING') [task1]`. In this case I will **not** return to the previous line, but instead I will put it at the start of the current statement where it belongs, e.g. in case I want to move the line somewhere else. See this video [this video] for reason why - it is good practice especially for beginners. There is also an eslint rule [LINK] to enforce that.

Recommends Qwerty · 2026-01 · Stack Overflow · on “Appropriate inline try catch”

It is much easier to learn when you **must** use a semicolon to avoid breaking something, rather than all the rules when you should and should not use it. Here [this video] is a great explanation.

Cites Michael Schwartz · 2016-05 · Stack Overflow · on “Why is Jquery click function requiring 2 clicks”

You can use JQuery's .click [LINK] with the .on [LINK] API. This way you target the specific button that's clicked and you can grab that buttons value with this.value Simple! To target if the button (that's clicked) has the class active you can use JQuery's .hasClass [LINK] API. This snippet uses ASI ( Automatic Semicolon Inversion [this video] ). $(document).ready(function() { $('.btn-group button').on('click', function() { $("#hidd").val( this.value ) /* To target just the class active you can do... if ($(this).hasClass('active') { $("#hidd").val( this.value ) } */ }) }) <script src=" [LINK] "></script> <div class="btn-group"> <button type="button" class="btn btn-default" value="150">150</butto

Cites Obsidian Age · 2017-09 · Stack Overflow · on “How to get an array of unique values from an array containing duplicates in JavaScript?”

It's now 2017, and according to **StandardJS** [LINK] , we should **not** use semicolons. They cite **these** [LINK] **three** [LINK] **references** [this video] for their reasoning.