It's not clear what this syntax means
const { headers, method, url } = request;
found in this tut https://nodejs.org/en/docs/guides/anatomy-of-an-http-transaction/
It's called destructuring operator
.
The destructuring assignment syntax is a JavaScript expression that makes it possible to unpack values from arrays, or properties from objects, into distinct variables.
Simple example:
var obj={
"a":2,
"b":3
}
let {a,b}=obj;
console.log(a,b);
From your example, I saw that request
is an object and the statement is translated to
headers = request.headers
But you can also apply destructuring operator
for arrays.
var foo = [1, 2, 3];
var [one, two, three] = foo;
console.log(one);
console.log(two);
console.log(three);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With