1

I am used to using arrow functions in TypeScript but sometimes I write small snippets of Vanilla JS for various reasons.

What happens in a browser that doesn't support arrow functions, like IE? Does it fail gracefully?

Tim Joyce
  • 4,487
  • 5
  • 34
  • 50
  • 1
    Browsers that don't support it will error out with a syntax error. I.e. your site won't work in those browsers. You decide whether you care about IE users/users with (significantly) older browsers. – deceze May 09 '19 at 12:40
  • In IE and IE Mobile it's a syntax error, so code won't run at all. – Pointy May 09 '19 at 12:40
  • You can refer this [compatibility](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions#Browser_compatibility) – Krishna Prashatt May 09 '19 at 12:40
  • No, it doesn't fail gracefully, it will throw a parse error and won't execute all the following code. I don't think we are ready yet, also because the cost of using babel is minimum, so better relying on it – Christian Vincenzo Traina May 09 '19 at 12:40
  • https://kangax.github.io/compat-table/es6/ – adiga May 09 '19 at 12:47
  • If you can use it without transpiling depends on for what target audience you want/have to develop. But I would always use syntax features in development that improve readability and maintainability and that can be transpiled without much polyfills or overhead. Hooking babel into an existing workflow shouldn't be a big problem. – t.niese May 09 '19 at 12:50
  • What do you mean with `fail gracefully`? Using an arrow function in a browser that does not support it is a syntax error, so you get an error message and the whole script is not executed. If you write `` then a alert with`test3` will appear, but no alert with `test1` or `test2`. So the second script won't be affected by the first one, which could be called graceful. – t.niese May 09 '19 at 12:58
  • @t.niese Honestly, this is an important question and I'm just trying to word it so the question isn't put on hold for being opinion based – Tim Joyce May 09 '19 at 13:01
  • @TimJoyce the first wording of your question was opinion based and unclear, so my first comment matched that question. After your edit the question you limit yourself to the _graceful_ part, and that's what my second comment is about. It is not clear what you mean with graceful, what kind of behavior you expect if it fails gracefully. I gave you an example that you could call graceful failing, but it is not clear if this is what you mean. – t.niese May 09 '19 at 13:08

0 Answers0