1

I'm sure this is a simple one - But I'm learning Javascript and executing programs through Node.js

function sumAll(arr) {

   var max = Math.max(...arr);
   console.log(max);

}

sumAll([1, 4]);

The error I have is:

SyntaxError: Unexpected token ...

I assume this is down to the ES6 spread operator? Is this not valid?

I have also tried to add the following, based on other StackOverflow answers I've found:

"use strict";

But this doesn't work either.

Any help appreciated - Thanks

Andrew Birks
  • 792
  • 9
  • 26

2 Answers2

4

Seems that you use outdated node.js version. Try to update your node.js to the latest version.

Ram
  • 143,282
  • 16
  • 168
  • 197
Eugene Tsakh
  • 2,777
  • 2
  • 14
  • 27
-1

Might be you are using outdated node.js version. Try to update your node.js with v6.10 or later on the latest version.

Ashish Gupta
  • 1,153
  • 12
  • 14