Difference between Compiler and Transpiler

Compiling and transpiling does have a really similar definition, but aren't equivalent processes. So, what's the difference?

Before we start, we have to understand higher & lower-level languages. Higher-level are languages more lacking concentration than lower-level languages. By abstracted we mean easier to understand. For example, you'd say machine language (binary) is lower level and closer to the pc than JavaScript. Higher-level languages generally are more simple to write down and understand, than writing a lower-level language (Assembly code for example) where you've got to know and affect memory addresses directly, etc.

What is Compiler?

The compiler takes the source code which is written in one language and then transforms it into another one or simply we can say translates a high-level language into assembly language or machine code. An example of some compiled languages is Java, C#, or C.

Code ---> Compiler ---> Executable(Machine Readable)

What is Transpiler?

Transcompiler may be a sort of compile also but instead of converting the ASCII text file to machine language, it converts ASCII text file in one application-oriented language or API to equivalent source code of another language or API. The best example for the Transpiler is the C++ compiler that translates C++ code to C code for later compilation and Babel for example can transpile ES6 JavaScript code into ES5 JavaScript and Typescript to Javascript.

Code(One language) ---> Transpiler ---> Code(Another language/Version)**

Transpiler is used for various reasons:

Compatibility: Generate code conforming to an older version while developers enjoy features of a more modern version, like with browsers not updated to the newest JavaScript standards.

Migration: Migrate legacy code to a modern programming language.

Performance: Initial code was written for quick prototyping or the project is moving to a special platform where another language is more suitable. Perhaps the target language features a better compiler which will generate more optimized code.