TypeScript, with or without semicolon? [duplicate]

0

I'm recently entering the world of angles, and I came across some tutorials where even imports and also codes are unfinished, followed by ;

Does it really need to be used?

And what's the difference between using and not using?

    
asked by anonymous 13.07.2018 / 22:11

1 answer

6

In theory, the semicolon requirement exists in a single scenario, which is when the next line starts with one of the following symbols:

  • [
  • (
  • '

For example:

var x = { xx : "hello", yy : "world"}
(function () {
    console.log("Hello World");
})();

Following the rule, the second line begins with a ( , so it is mandatory to use ; at the end of the first / beginning of the second, thus:

 var x = { xx : "hello", yy : "world"};
(function () {
    console.log("Hello World");
})();

The reason for the existence of the semicolon in this scenario is somewhat complex, and well addressed in this article .

Therefore, you can, for the most part, simply ignore the semicolon at the end of the sentences.

However, when we talk about coding standarts , we recommend using ; whenever necessary .

I particularly adopt the pattern of always putting ; , where appropriate. I think it makes the code more readable and standardized.

    
13.07.2018 / 22:28