Rules Hub
Coding Rules Library
← Back to all rules
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
frontend ruleP2universalStack: typescript
domreadability
Prefer firstElementChild over children[0]
Use semantic DOM accessors (firstElementChild, lastElementChild) instead of positional indexing into children; they state intent and are typed with null in the contract.
PR: FCK-3307 Improve the order of <head> elementsCreated: Jul 16, 2026
Bad example
Old codets
| 1 | const first = head.children[0]; |
Explanation (EN)
Index access hides the intent and its undefined case is easy to forget.
Objašnjenje (HR)
Indeksni pristup skriva namjeru, a undefined slučaj se lako zaboravi.
Good example
New codets
| 1 | const first = head.firstElementChild; |
Explanation (EN)
The accessor says exactly what is being read and the nullable type is explicit.
Objašnjenje (HR)
Accessor kaže točno što se čita, a nullable tip je eksplicitan.