Babel and SWC interview questions

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?

  1. To minify and compress JavaScript files
  2. To bundle multiple files into one
  3. To convert modern JavaScript to ES5-compatible syntax for older browsers
  4. 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?

  1. SWC skips transpilation of large files
  2. SWC doesn't transpile JSX or TypeScript
  3. SWC removes all comments
  4. 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?

  1. No, Babel can only transpile syntax; runtime features require polyfills
  2. Yes, always
  3. Yes, but only for Promise and Array methods
  4. 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?

  1. Minify code
  2. Bundle files
  3. Convert modern JavaScript into compatible code
  4. 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?

  1. It skips JSX
  2. It caches nothing
  3. It uses fewer plugins only
  4. 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?

  1. No, they only strip types
  2. Yes, fully
  3. Only in production
  4. 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?

  1. File size
  2. Your browser or Node targets
  3. Git history
  4. 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?

  1. New syntax rules
  2. Type checking
  3. Missing runtime features such as Promise
  4. 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?

  1. Writing JSX
  2. Using components
  3. Using hooks
  4. 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?

  1. A minifier such as Terser
  2. Babel
  3. Prettier
  4. 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?

  1. By editing text with regex
  2. By visiting and modifying the AST
  3. By running the code
  4. By downloading packages
Show answer

Answer: By visiting and modifying the AST

Plugins traverse the syntax tree.

Lesson: Quick Reference & Cheat Sheet

← Back to the course