Question presented to candidate: "Angular templates are not JavaScript, yet the browser runs them. Explain the difference between AOT and JIT compilation, which one a production build uses, and what would concretely get worse if we switched to JIT."
What a strong answer should cover:
- Both turn templates and decorators into JavaScript instructions; the difference is when: at build time (AOT, Ahead-of-Time) or in the browser at startup (JIT, Just-in-Time).
- AOT is the default for
ng buildandng serve(aotdefaults to true); JIT ships@angular/compilerto the browser. - AOT gives smaller bundles, faster startup (no compile step in the browser) and build-time errors: template type-checking and syntax errors fail the build instead of a user's session.
- AOT is required for modern APIs: signal
input(),model()and signal queries rely on the compiler; plain JIT cannot see them. - JIT still appears in tests and tooling (for example
TestBedcompiling components, or partially compiled libraries without the linker). - AOT is also safer: no runtime template compilation means no
eval-style template injection.
Clarifying questions expected:
- "Production builds only, or also tests and the dev server?"
- "Should I go into what the compiled output looks like?"
Code / implementation expected: Optional — the same component compiled both ways, or a template error that only AOT catches.