4 ms·
Always prepend ( and [ with ; I also prefer void function () {} for this. Void the result of this function expression which I immediately invoke.
by adrianhel 8y ago
Always prepend ( and [ with ;
I also prefer void function () {} for this. Void the result of this function expression which I immediately invoke.
- adrianhel 8y agoCorrection: void function () {}()
- ezekg 8y agoI'm not sure always prepending those with ";", but definitely when needed, sure. But most of the time you can simply refactor the code a little bit and improve readability with the addition of a single variable.
- Klathmon 8y agoMore correctly it's: Always prepend any line that begins with ( and [ and ` with ;
- adrianhel 8y agoAlways for ( and [ when they start a statement. It really is that simple.
- adrianhel 8y agoAnd for template strings: ` I do agree that good use cases are few and far between.
- dvlsg 8y agoI honestly can't remember a recent time I had to start a line with a ( or a [. I don't really write IIFEs since let and const. I'm sure the outputs from babel/typescript/etc use them, but I don't really need to write them myself, now that we have proper block scoping. And if I want to declare an array and immediately iterate over it, I just put it in a variable first. That gives it a name, too, which tends to improve readability anyways. I work with Javascript / Typescript projects on both sides of the argument, and I have to say not using semicolons never seems to cause any problems. Especially not with auto formatting / linters around.
- marshall313 8y agoI agree. Those are the only two cases where a semicolon is needed. Other than that, I like my code to look clean :)