Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if you have written ES6 code?

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?

like image 479
Thomas Wagenaar Avatar asked Jul 28 '17 15:07

Thomas Wagenaar


People also ask

How do I know if my browser supports ES6?

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.

How do I know what version of ECMAScript I have?

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.

Is JavaScript and ES6 same?

ECMAScript 2015 was the second major revision to JavaScript. ECMAScript 2015 is also known as ES6 and ECMAScript 6.


2 Answers

http://jshint.com/ or http://www.jslint.com/ - will detect ES6 specific specifications by just adding your code in the console

like image 111
23rharris Avatar answered Oct 09 '22 20:10

23rharris


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

like image 7
Jonathan Wood Avatar answered Oct 09 '22 18:10

Jonathan Wood