For ... let... of disallowed?

Hi. I am trying to do a for…let…of https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for

for(let number of parts) {
if (isNaN(parseFloat(number))) valid = false;
}
// parts is an array of chars.

Which got converted on codepen.io to…

for (let number of parts) {
if (window.CP.shouldStopExecution(4)) {
break;
}
if (isNaN(parseFloat(number)))
valid = false;
}

Any way around this? I realise it is only in ECMA 6.0 http://www.ecma-international.org/ecma-262/6.0/#sec-for-in-and-for-of-statements

Did you try Pen Settings > JavaScript -> JavaScript Preprocessor > Babel?

I don’t know which ES6 transformations Codepen is using but I assume all of ES2015.

2 Likes

That’s fixed it. Thanks for that. What is Babel?

It produces JavaScript that will run on older JS interpreters that only support ES5 or some of ES6. It also allows you to try out proposed language features that are experimental or slated to be added to future releases of JavaScript.

Enjoy!

1 Like