0

What does something like this achieve?

function myFunction(foo, bar={}, boo){
//?
}
fancy
  • 48,619
  • 62
  • 153
  • 231
  • This is not valid javascript. Did I miss something? – Robin Jul 16 '12 at 02:27
  • 2
    `SyntaxError: Unexpected token =` – Andreas Wong Jul 16 '12 at 02:31
  • 1
    Are you running some sort of preprocessor to your Javascript? That would be the only way to make something like this work. It would be easy enough to write a preprocessor that interpreted that in the way it's obviously intended. But I've never seen one. – Scott Sauyet Jul 16 '12 at 02:38

2 Answers2

3

This is not valid JS. In other languages this will set the argument to the value {} if bar is not specified, but it would only make sense if the default value was the last argument, or the arguments could be named when the function is called.

Adam Bergmark
  • 7,316
  • 3
  • 20
  • 23
  • This answer doesn't answer his question. It is possible to pass an object to a function!!! Although his code sample isn't working, his question should be answered... – ˈvɔlə Dec 16 '13 at 12:58
  • I assumed he asked what `foo = {}` syntax as a parameter declaration meant since that was the code he wrote. And my answer was accepted... – Adam Bergmark Dec 16 '13 at 17:47
1

It achieves SyntaxError: Unexpected token = i.e. its not valid JavaScript

Musa
  • 96,336
  • 17
  • 118
  • 137