Describe the process of tree shaking in JavaScript modules.
Instruction: Explain what tree shaking is and how it benefits JavaScript applications.
Context: This question tests the candidate's understanding of modern JavaScript build tools and optimization techniques.
Updated
Official answer available
Read the opening below, then unlock the full answer and practical guidance.
Tree shaking removes code a build tool can prove is unnecessary, commonly by following statically analyzable ES module imports and exports. It differs from minification, which also shortens identifiers and syntax, and from code splitting, which puts code into separately loadable assets.
Suppose a module exports add and multiply, but the entry imports only add...