9

Is this possible? Example:

var parts = [1,2,3,4,5];
for (part of parts) {
    console.debug(part);
}

I want to detect if doing this is possible.

2
  • 2
    Also, kangax.github.io/es5-compat-table/es6. Source. Commented Aug 17, 2013 at 1:41
  • If you hover over the (C) icon in the table @JonathanLonowski links to, it shows the source of his test for that feature. Commented Aug 17, 2013 at 1:48

1 Answer 1

9

You can always try-catch such stuff. But you need eval as well, as some javascript engines will bail with a SyntaxError early.

try {
  eval("for (var i of []);");
  console.log("yep");
} catch(ex) {
  console.log("nope");
}

Tested in Firefox ("yep") and Chrome ("nope").

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.