Saturday, 13 May 2017

Why my explicit array -[ ]- with a proto method doesn't work without something before?

I have this code in Node 7.8.0:

function myfunction(n) {
   n = 3
   [].forEach(n => "do something")    
}

It returns:

   [].forEach(v => "do something")    
    ^
SyntaxError: Unexpected token ]

But if I add something before the brackets like a semicolon or a variable declaration it runs without errors. Just like this:

function myfunction(n) {
   n = 3;
   [].forEach(n => "do something")    
}

I am so confused about this.



via Carlos Govea

No comments:

Post a Comment