1.2 KiB
Style Guide
In addition, to VS Code's coding guidelines, please adhere to the following:
-
Use
for ... ofwhenever possibleRationale:
for ... ofis awesome. It's more readable than any other variant. -
Don't use
anyas much as possibleRationale: The language is called TypeScript, not UntypedScript. 😉 Static typing is wonderful. It catches bugs and improves readability. We should strive to use it as much as possible.
-
Use
constwherever possible.Rationale: Instead of reading
constas "constant value," read it as "single assignment." Yes, it means "constant value" in other programming languages, but it's a little different in JavaScript. -
When we can't use
const, uselet; nevervarRationale:
vartrips up programmers in a number of cases - hoisting and closure capture are two big ones. Consider the difference betweenfor (var j = 0; j < 5; j++) { setTimeout(() => console.log(j), 5) }and
for (let j = 0; j < 5; j++) { setTimeout(() => console.log(j), 5) }Even if you're not capturing the variable, who knows if someone else might later?