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

14th May 2017, 3:01 AM
ź¹€ģ •ģ œ(Legacy)
ź¹€ģ •ģ œ(Legacy) - avatar
8 Answers
+ 1
Most mobile webview still not support ECMA6.
14th May 2017, 3:37 AM
CalviÕ²
CalviÕ² - avatar
+ 8
@Calvin Yes I play it in SoloLearn Code Playground.
14th May 2017, 3:10 AM
ź¹€ģ •ģ œ(Legacy)
ź¹€ģ •ģ œ(Legacy) - avatar
+ 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)
14th May 2017, 3:26 AM
ź¹€ģ •ģ œ(Legacy)
ź¹€ģ •ģ œ(Legacy) - avatar
+ 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.
14th May 2017, 3:31 AM
ź¹€ģ •ģ œ(Legacy)
ź¹€ģ •ģ œ(Legacy) - avatar
+ 8
@Calvin Oh thanks... I didn't know that... I should code in sololearn web version from now on.
14th May 2017, 3:41 AM
ź¹€ģ •ģ œ(Legacy)
ź¹€ģ •ģ œ(Legacy) - avatar
+ 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
14th May 2017, 5:47 AM
visph
visph - avatar
+ 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.
14th May 2017, 3:13 AM
CalviÕ²
CalviÕ² - avatar
+ 1
Were you running it in code playground? Code that run in Code playground are directly run from SL server. It should support let.
14th May 2017, 3:06 AM
CalviÕ²
CalviÕ² - avatar