Can I catch an error from async without using await?

Dealing with unhandled rejected native promises (and async/await uses native promises) is a feature supported now in V8. It’s used in the latest Chrome to output debugging information when a rejected promise is unhandled; try the following at the Babel REPL: async function executor() { console.log(“execute”); } async function doStuff() { console.log(“do stuff”); throw new … Read more

IE does not support Array includes or String includes methods

Because it’s not supported in IE, it is not supported also in Opera (see the compatibility table), but you can use the suggested polyfill: Polyfill This method has been added to the ECMAScript 2015 specification and may not be available in all JavaScript implementations yet. However, you can easily polyfill this method: if (!String.prototype.includes) { … Read more

What is after Internet Explorer 11 on Windows 7? How well will ES2016 be supported in enterprises?

With JavaScript now being updated each year (ES2015, ES2016, ES2017, etc.), how does Microsoft plan to keep IE 11 up to date? They’re not going to. As of 2015, Internet Explorer 11 will no longer be receiving any new features or platform bug fixes. Only security updates will be provided to IE11 from here on … Read more

VSCode Linter ES6 ES7 Babel linter

How I proceed: install globally eslint : npm install -g eslint install babel-eslint : npm install –save-dev babel-eslint install eslint-plugin-react : npm install –save-dev eslint-plugin-react create .eslintrc file in you root directory. here is my config: { “env”: { “browser”: true, “node”: true, “es6”: true, “jest”: true, “jquery”: true }, “parser”: “babel-eslint”, “parserOptions”: { “ecmaVersion”: … Read more

Best way to polyfill ES6 features in React app that uses create-react-app

Update: The create-react-app polyfill approach and docs have changed since this question/answer. You should now include react-app-polyfill (here) if you want to support older browsers like ie11. However, this only includes the “…minimum requirements and commonly used language features“, so you’ll still want to use one of the approaches below for less common ES6/7 features … Read more

Array.prototype.includes vs. Array.prototype.indexOf

tl;dr: NaN is treated differently: [NaN].indexOf(NaN) > -1 is false [NaN].includes(NaN) is true From the proposal: Motivation When using ECMAScript arrays, it is commonly desired to determine if the array includes an element. The prevailing pattern for this is if (arr.indexOf(el) !== -1) { … } with various other possibilities, e.g. arr.indexOf(el) >= 0, or … Read more

How do I destructure all properties into the current scope/closure in ES2015?

I think you’re looking for the with statement, it does exactly what you are asking for: const vegetableColors = {corn: ‘yellow’, peas: ‘green’}; with (vegetableColors) { console.log(corn);// yellow console.log(peas);// green } However, it is deprecated (in strict mode, which includes ES6 modules), for good reason. destructure all properties into the current scope You cannot in … Read more

Can I fire and forget a promise in nodejs (ES7)?

Yes, you can do that, and it will run the two asynchronous functions in parallel. You’ve just created a promise and thrown it away. However, this means that when the promise is rejected you won’t notice. You’ll just get an unhandledRejection eventually which will crash your process if not handled. Is this OK? How can … Read more

tech