JavaScript and semicolon

'use strict'
[1,2,3,4].find(x => x > 1)

When the above code runs with nodejs 5.0.0, it gives the following error:

TypeError: "use strict"[(((1 , 2) , 3) , 4)].find is not a function
at Object.<anonymous> (C:\src\nodejs\ecma6.js:2:11)
at Module._compile (module.js:425:26)
at Object.Module._extensions..js (module.js:432:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:311:12)
at Function.Module.runMain (module.js:457:10)
at startup (node.js:136:18)
at node.js:972:3

The error will be removed if I add a semicolon after "use strict".

It looks like an error ... or is there something deeper - it means if there is a list of exceptional cases in the language specification that requires a semicolon.

Update

The language specification lists exceptional cases in which explicit semicolons are required.

+4
source share
1 answer

, javascript. , , , :

"use strict"[1,2,3,4] ...

, :

"use strict"[4] ...

- . "s".

:

"s".find()

find.

, , , - .


:

ECMAScript ( , ES5). 7.9.1 1 , :

, , ( ), , ​​ , :

  • , , LineTerminator.

  • }.

"use strict" [1,2,3,4].... :

"use strict"[1,2,3,4]...

, javascript. , " ".

+7

Source: https://habr.com/ru/post/1615349/


All Articles