How are function declarations hoisted?
Fully hoisted: name and body available before definition. Can be called before declaration.
Why avoid deeply nested logic?
Reduces readability and complexity. Avoid by breaking functions down and using early returns.
What is the Single Responsibility Principle (SRP)?
A function should have one responsibility and one reason to change. Makes code modular and testable.
Advantages of arrow functions?
Concise syntax and lexical this binding to avoid context issues.
What are template literals?
Strings using backticks with interpolation and multiline support.
What is modular code and why important?
Organized, reusable units. Improves reusability, maintainability, and testing.
How does inline caching work?
Stores property lookup results for reuse, avoiding repeated lookups.
Impact of hidden classes on performance?
Optimize property access if objects share shape. Different shapes reduce performance.
What are the 7 primitive data types?
string, number, boolean, null, undefined, symbol, bigint.
What are reference types?
Objects, arrays, functions. Complex structures stored by reference.
Explain copy by value in JS.
Primitives copied independently. Changes do not affect the copy.
Explain copy by reference in JS.
References copied. Both point to same object. Changes affect all references.
Difference between == and ===?
== compares after type conversion.
=== compares without conversion. Prefer ===.
typeof null result?
typeof null === ‘object’ (historical bug).
Explain reference counting GC.
Counts references. When zero, object reclaimed. Fails with circular refs.
Purpose of nullifying references?
Set to null to signal GC object no longer needed.
Why avoid unnecessary objects?
Too many temps strain GC. Reuse objects when possible.
What is an object pool?
Reuse pre-initialized objects to reduce GC overhead.