1

Referring to this page: https://cloud.google.com/functions/docs/writing/http

In the code excerpt below, the first assignment statement is inside parentheses. Is there any benefit to doing that? I omitted them with no apparent loss of functionality, but wondering if I might be missing out on some desired behavior.

switch (req.get('content-type')) {
    // '{"name":"John"}'
    case 'application/json':
      ({name} = req.body);
      break;

    // 'John', stored in a Buffer
    case 'application/octet-stream':
      name = req.body.toString(); // Convert buffer to a string
      break;
royappa
  • 663
  • 1
  • 9
  • 20
  • 1
    its possible case blocks might start with a "{" which could be confusing to the compiler or to someone reading the code. – Rick Jan 18 '21 at 00:58
  • 3
    Does this answer your question? [object destructuring without var](https://stackoverflow.com/questions/27386234/object-destructuring-without-var) – user202729 Jan 18 '21 at 01:03
  • @user202729 That must be it because I used a "const" without even thinking (and without the const there is an error). Please post as an answer so I can accept. Thanks! – royappa Jan 18 '21 at 04:30

0 Answers0