javascript – Is it possible to check for browser support for let, and create an alias for var?


Contrary to the documentation, block-visible variables declared with let only work since Firefox 44 and Chromium 49 . In this case, the browser ( Chrome 47 ), having read the let= construction, let= error in and stops the execution of all scripts.

1 How to tell if the browser is working with let block variables without parsing the userAgent ?

2 I'm already silent about let emulation, but is it possible to create / redefine alias to var if the browser does not know how to work with let ?

3 Is it possible to make block let variables work on older versions of Chromium and on Samsung Internet ?



<script type="application/javascript">
    'use strict';
    try{eval('let test');}catch(e)
        alert('К сожалению, Ваш браузер, морально устарел и не поддерживается нами. :-(\n\nПожалуйста, используйте актуальные и безопасные версии современных браузеров:\n\nFirefox:\n\nChrome:\n\nПри закрытии этого окна вас перенаправит на страницу загрузки браузера Firefox.\n\nПожалуйста, установите или обновите этот браузер, используя подсказки установщика, и обязательно возвращайтесь к нам! :-)\n\n'+location+'\n\n');

2 Cannot define alias or syntax reference in JavaScript .

3 Possibly with the 'use strict' directive ; make block let variables understand on Chromium 41+ and Samsung Internet 4 browsers, and also let the JavaScript interpreter optimize the code even better.

Read more: Strict mode and let support

Scroll to Top