I found a code snippet on this site for parsing cookies. Credit to Pomax for posting it here. There is some syntax in the code that I don't understand:
function parseCookies (headers) {
const list = {};
const { Cookie } = headers;
if (!Cookie) return list;
Cookie.split(`;`).forEach((cookie) => {
let [ name, ...rest] = cookie.split(`=`);
name = name?.trim(); //What is this doing?
if (!name) return;
const value = rest.join(`=`).trim();
if (!value) return;
list[name] = decodeURIComponent(value);
});
return list;
};
The syntax I don't understand is here:
name = name?.trim();
Can someone help me understand what the ?
is doing, and possibly point me to where it's documented in the MDN Web Docs?
Thank you!