I know some basics of JavaScript and new to ES6.
I just tried a simple ES6 feature import and export and it seems that it doesn't support browser. I searched and came to know that we must use any transpiler(babel) to convert the ES6 to ES5.
So, the import/export converted to CommonJs syntax. If it is like this then I can directly use CommonJs!?
- If ES6 is ready then why latest browser doesn't support yet?
- If Ihave to convert my ES6 to ES5 then why I have to code on ES6? I can direclty use ES5!
Index.html
<!DOCTYPE html>
<html>
<head>
<title></title>
<script src="main.js" type="text/javascript"></script>
</head>
<body>
</body>
</html>
main.js
import {square} from 'func';
console.log( square(6));
func.js
export function square(x) {
return x * x;
}
Update
It's not duplicate of any answered questions, the referenced one was answered 5 years back. We are in JavaScript where every Monday we get new news ;)