Skip to content

strange behaviour of [] in start of the line #13099

@pvinis

Description

@pvinis

Version: v7.9.0
Platform: Darwin green.local 16.5.0 Darwin Kernel Version 16.5.0: Fri Mar 3 16:52:33 PST 2017; root:xnu-3789.51.2~3/RELEASE_X86_64 x86_64

so i have this in a file

console.log('hello')

const a = 2

[3,4].forEach(n => console.log(n))

and when doing node weird.js i get

[3,4].forEach(n => console.log(n))
     ^

TypeError: Cannot read property 'forEach' of undefined
    at Object.<anonymous> (/Users/pvinis/Desktop/weird.js:3:6)
    at Module._compile (module.js:571:32)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12)
    at Function.Module._load (module.js:439:3)
    at Module.runMain (module.js:605:10)
    at run (bootstrap_node.js:423:7)
    at startup (bootstrap_node.js:147:9)
    at bootstrap_node.js:538:3

also https://es6console.com/j2uho344/ this might be helpful.

i saw that Array(3,4).forEach.. works fine.

is that a bug? is that on purpose like that?

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionIssues that look for answers.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions