+ 9
[JavaScript] Why "try-catch" statement don't catch this error?
I want to show alert message if user's device do not support ECMA6 Syntax. So I thought following script will work. /* Script ----------------------- try { let a = 1; // "let" keyword is only supported some mobile device(I think android version >= 5.1) } catch(e) { alert("Not Supported in your device.\n" + navigator.userAgent); } ------------------------------*/ But it didn't catch error. (My android version is 4.4.2) And console says "SyntaxError"... Please tell me the reason.
8 Réponses
+ 1
Most mobile webview still not support ECMA6.
+ 8
@Calvin
Yes I play it in SoloLearn Code Playground.
+ 8
@Calvin
My device is tablet(not phone) but
alert(navigator.userAgent) says
Mozilla5.0 (Linux; Android 4.4.2; LG-V700n Build/...)
so i thought my device is android.
Is this the cause of problem?(the fact that my device is not a phone)
+ 8
@Calvin
When I run it in webversion, "let" works
but when I run it in Application, it didn't work.
maybe my device need web's support.
+ 8
@Calvin
Oh thanks... I didn't know that...
I should code in sololearn web version from now on.
+ 6
@Calvin wrote: << Most mobile webview still not support ECMA6. >>
It seems to be from less to less true, and recent versions of android/webview already support them ;)
Anyway, you can use Babel to support ES6 in browsers not yet supporting it:
https://www.sololearn.com/Discuss/382066/javascript-template-literals-and-arrow-functions
+ 2
Code that run in Code playground are directly run from SL server. It should support let.
To verify your code can be run from your phone, you need to save it as local file, open directly from your phone.
+ 1
Were you running it in code playground?
Code that run in Code playground are directly run from SL server. It should support let.