I have written a bunch of Javascript code. I was never aware of the fact that there are multiple JS 'versions', like ES5 and ES6.
I now have this project hosted on Github, and somebody pointed out that because i'm using ES6 code, I might need to convert it to ES5 with Babel.
However, I have no idea which parts of my code use ES6. I could read all of the ES6 specifications, but is there some kind of tool/checker which marks all of the ES6 code in my project?
var supportsES6 = function() { try { new Function("(a = 0) => a"); return true; } catch (err) { return false; } }(); The critical test is the a = 0 . All browsers supporting default parameters have a fairly complete support of ES6 — for example, Edge 13 will be rejected by this test despite a decent ES6 coverage.
ECMAScript support different object on each version. To detect the ECMAScript version we can check the object exits into a browser or not. If that object is identified that means ECMA Version supported into the browser.
ECMAScript 2015 was the second major revision to JavaScript. ECMAScript 2015 is also known as ES6 and ECMAScript 6.
http://jshint.com/ or http://www.jslint.com/ - will detect ES6 specific specifications by just adding your code in the console
Add it into the Babel repl and see if it changes:
https://babeljs.io/repl/
:-) Hope that helps
Other than that it might be best to setup es6 with babel using webpack, gulp, rollup etc
So that if you write es6 or es5 it will automatically get converted and you can learn some new features on the way while still supporting es5 only browsers
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With