• Resolved Jacob N. Breetvelt

    (@opajaap)


    Are we – developers – allowed to use const in javascript?
    In other words, is it ok to assume that the visitors most recent browser update is not earlier than september 2016?

    I want to use this construction and using const is cheaper than using var

    function myFunc( arg1, arg2 ) {
    const $ = jQuery;
    
    var mySelection = $( '.myclass' );
    // etc
    }
Viewing 2 replies - 1 through 2 (of 2 total)
  • > In other words, is it ok to assume that the visitors most recent browser update is not earlier than september 2016?

    One tool you can use to see what browsers support a specific JavaScript syntax is caniuse.com. For example, for const there’s https://caniuse.com/#search=const

    It looks like const is widely supported by browsers other than IE10 and before. However, it seems to be little gotchas (and potential issues) with many of them if you rely on what makes const great: block scope. If your concern is performance, I’d suggest that you should be fine using var as browsers are good at optimizing code.

    If you still were interested in using the new JavaScript constructs that were created after ES6 (const, let, etc) but still wanted to support old browsers, perhaps this guide on how to work with modern JavaScript would be useful.

    Thread Starter Jacob N. Breetvelt

    (@opajaap)

    Thank you. I will stick to var, just to be safe, and believing you with respect to browsers being good at optimizing code.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘const in js’ is closed to new replies.