JavaScript Interview Question #164

What is transpilation in JavaScript?

Performance, Browser APIs, Rendering & Modern Web Architecture Senior Advanced

Quick Interview Answer

Transpilation converts source code from one JavaScript form into another, often to support environments that do not understand newer syntax directly. Tools such as Babel can transform selected modern language features according to configured browser targets.

Detailed Explanation

Transpilation converts source code from one JavaScript form into another, often to support environments that do not understand newer syntax directly. Tools such as Babel can transform selected modern language features according to configured browser targets.

Transpilation handles syntax transformations, but missing runtime APIs may require polyfills. Modern projects should target actual supported environments rather than transpiling everything unnecessarily.

Code Example

// Modern source:
const greet = name => `Hello ${name}`;

// A transpiler may produce older-compatible syntax:
var greet = function (name) {
    return "Hello " + name;
};