11 questions from the Babel and SWC: JavaScript Transpilation and Build Speed course, each with the correct answer and an explanation. Try to answer before you open the answer.
Module 10: Interview Prep & Cheat Sheet
1. What is the primary purpose of Babel?
- To minify and compress JavaScript files
- To bundle multiple files into one
- To convert modern JavaScript to ES5-compatible syntax for older browsers
- To manage npm packages
Show answer
Answer: To convert modern JavaScript to ES5-compatible syntax for older browsers
Babel transpiles modern JavaScript to compatible older syntax. Minification and bundling are separate concerns handled by other tools.
Lesson: Common Interview Questions
2. Why is SWC faster than Babel?
- SWC skips transpilation of large files
- SWC doesn't transpile JSX or TypeScript
- SWC removes all comments
- SWC is written in Rust and compiled to native code, while Babel is interpreted JavaScript
Show answer
Answer: SWC is written in Rust and compiled to native code, while Babel is interpreted JavaScript
SWC's Rust implementation enables massive performance gains. Compiled native code is far faster than interpreted JavaScript for CPU-intensive parsing and AST transformation.
Lesson: Common Interview Questions
3. Can Babel add runtime features that don't exist in the target browser?
- No, Babel can only transpile syntax; runtime features require polyfills
- Yes, always
- Yes, but only for Promise and Array methods
- Only in Chrome
Show answer
Answer: No, Babel can only transpile syntax; runtime features require polyfills
Babel transpiles syntax but cannot create functions that don't exist. For runtime features like `Promise.all()` or `Array.prototype.includes()`, use polyfills like core-js.
Lesson: Common Interview Questions
4. What is the main purpose of Babel?
- Minify code
- Bundle files
- Convert modern JavaScript into compatible code
- Run tests
Show answer
Answer: Convert modern JavaScript into compatible code
It transforms syntax for your target environments.
Lesson: Quick Reference & Cheat Sheet
5. Why is SWC faster than Babel?
- It skips JSX
- It caches nothing
- It uses fewer plugins only
- It is written in Rust and compiled to native code
Show answer
Answer: It is written in Rust and compiled to native code
Native code and parallelism speed it up.
Lesson: Quick Reference & Cheat Sheet
6. Do Babel and SWC type-check TypeScript?
- No, they only strip types
- Yes, fully
- Only in production
- Only with plugins
Show answer
Answer: No, they only strip types
Run tsc --noEmit for type checking.
Lesson: Quick Reference & Cheat Sheet
7. What does @babel/preset-env use to decide what to transpile?
- File size
- Your browser or Node targets
- Git history
- Package name
Show answer
Answer: Your browser or Node targets
Targets come from browserslist or the targets option.
Lesson: Quick Reference & Cheat Sheet
8. What do polyfills add?
- New syntax rules
- Type checking
- Missing runtime features such as Promise
- Minification
Show answer
Answer: Missing runtime features such as Promise
Syntax transforms cannot add runtime APIs.
Lesson: Quick Reference & Cheat Sheet
9. What does the automatic JSX runtime remove the need for?
- Writing JSX
- Using components
- Using hooks
- Importing React in every file
Show answer
Answer: Importing React in every file
The compiler injects jsx() from react/jsx-runtime.
Lesson: Quick Reference & Cheat Sheet
10. Which tool compresses variable names and whitespace?
- A minifier such as Terser
- Babel
- Prettier
- tsc
Show answer
Answer: A minifier such as Terser
Transpilation and minification are separate steps.
Lesson: Quick Reference & Cheat Sheet
11. How does a Babel plugin change code?
- By editing text with regex
- By visiting and modifying the AST
- By running the code
- By downloading packages
Show answer
Answer: By visiting and modifying the AST
Plugins traverse the syntax tree.
Lesson: Quick Reference & Cheat Sheet