Curly braces inside JavaScript arguments for functions

milan picture milan · Nov 10, 2010 · Viewed 21.6k times · Source

What do the curly braces surrounding JavaScript arguments for functions do?

var port = chrome.extension.connect({name: "testing"});
port.postMessage({found: (count != undefined)});

Answer

Matthias Winkelmann picture Matthias Winkelmann · Nov 14, 2015

A second possible answer has arisen since this question was asked. Javascript ES6 introduced Destructuring Assignment.

var x = function({ foo }) {
   console.log(foo)
}

var y = {
  bar: "hello",
  foo: "Good bye"
}

x(y)


Result: "Good bye"