Many computer languages are running, we need to compile the source code to the computer at the bottom of the language;
While JavaScript is an interpreted language, the browser receives JavaScript text and then interprets execution, so after writing JavaScript code, the browser can directly recognize the text without having to compile JavaScript text.
However, with the continuous updating and versioning of JavaScript, new syntax and features are becoming more and more numerous. These syntaxes provide a better performance, programming experience, and development style, and browsers follow the new syntax and features very slowly, meaning that the new JavaScript features are not directly available.
This is the background of Babel's appearance.
The versions of JavaScript include ES3, ES5, ES6, and ES7, and not all browsers support all of these versions.
In order to allow developers to use the latest JavaScript version after the advent of new versions of JavaScript, Babel appears.
Babel allows developers to develop applications using the latest JavaScript version and new syntax. It can convert the latest syntax into a syntax that all browsers can support today.
For example, you can now use the new syntax of ES6 and even ES7, and of course, react JSX syntax, and use Babel to translate these syntaxes into ES5 syntax that the current browser can support.
In the previous article, Babel was referenced directly in the browser:
<script src= "Https://unpkg.com/babel-standalone@6.15.0/babel.min.js" ></script>
Then, write the JSX JavaScript code in the script label with type Text/babel:
<script type= "Text/babel" >
function formatname (user) {return
User.firstname + ' + user.lastname;
}
Const USER = {
firstName: ' Harper ',
lastName: ' Perez '
};
const ELEMENT = (
In the product mode, this method is not suitable for use.
Babel can also provide transformations in loader ways in tools such as Webpack.