0

I'm learning javascript, I'm a beginner to programming so forgive me if this is obvious, but people seem to write function code like so

function IamAFunction(number) {
  return number * 2;
};

why is there a semicolon at the end of the 2nd curly brace. I've written code without the semi colon at the end and it works fine. Why do so many people write functions this way, I understand the semicolons use at the end of an expression, but not function.

  • 1
    because someone put it there? It is a style preference. Some people/style guildes use no semicolons at all. – epascarello Jul 06 '20 at 15:36
  • semicolons are technically optional in Javascript. – chevybow Jul 06 '20 at 15:38
  • 1
    Related: https://stackoverflow.com/questions/444080/do-you-recommend-using-semicolons-after-every-statement-in-javascript – Anurag Srivastava Jul 06 '20 at 15:38
  • @epascarello I think the same. Also you can read this web article **Javascript Standard Style** (https://standardjs.com). That is help to understand JS style when you are write some JS code. – Minwoo Kim Jul 06 '20 at 15:41
  • There should not be a semi colon after a function. It's only needed after an expression. – Coffee bean Jul 06 '20 at 15:46
  • Unfortunately, it's more than just a stylistic thing. [When not used after expressions, bad things can happen.](https://stackoverflow.com/questions/45507953/how-does-avoiding-semicolons-improve-javascript-code/45507978#45507978) – Scott Marcus Jul 06 '20 at 15:47

0 Answers0