Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

So i'm using Javascript const keyword, what happens in IE?

I understand that the const keyword has been already implemented across the board in browsers except for IE10 versions, but is it viable? If someone jumps on my site on IE10< will the "const" keyword be re-assigned to "var"? if not will the whole site fail? the MDN docs on the const keyword give a handy chart at the bottom which tells me that not only IE, but rather many Mobile browsers do not support it either. should i just scrap it and use var?

like image 788
lluisrojass Avatar asked May 04 '16 19:05

lluisrojass


2 Answers

IE11 and above supports const but IE10 and below do not.

If you attempt to use const in any browser that does not support it, you will get a syntax error. If you must support older browsers, you cannot use const unless you use a transpiler to compile your code down into ES5. Babel is a good example of such a transpiler.

like image 62
Mike Cluck Avatar answered Oct 27 '22 16:10

Mike Cluck


Take Babel, the ECMAScript 2015 (ES6) to ECMAScript 5 transpiler.

If you write:

const a = 123;

It outputs:

"use strict";

var a = 123;

If the potential of breaking your code on unsupported browsers isn't enough, i think that should be.

like image 40
Marco Scabbiolo Avatar answered Oct 27 '22 15:10

Marco Scabbiolo