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.

Gabriel Nahmias
  • 920
  • 3
  • 15
  • 20
  • 2
    Also, http://kangax.github.io/es5-compat-table/es6/. [Source](https://github.com/kangax/es5-compat-table/blob/1b978c9403b281e3c6bbdbcee2b6f1eda561cd07/es6/index.html#L409-L417). – Jonathan Lonowski Aug 17 '13 at 01:41
  • If you hover over the (C) icon in the table @JonathanLonowski links to, it shows the source of his test for that feature. – Heretic Monkey Aug 17 '13 at 01:48

1 Answers1

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").

nmaier
  • 32,336
  • 5
  • 63
  • 78