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
  • 642
  • 6
  • 25

2 Answers2

4

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

Ram
  • 140,563
  • 16
  • 160
  • 190
Eugene Tsakh
  • 2,645
  • 2
  • 13
  • 26
-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
  • 998
  • 9
  • 13