Search code examples
javascriptinternet-explorerconstantsecmascript-5

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?


Solution

  • 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.