function getId(user, fallback) { return user && user.id ?? fallback; }
You can’t mix the nullish coalescing operator ?? with && (or ||) in the same expression without parentheses.
function getId(user, fallback) { return (user && user.id) ?? fallback; }
or even better, just use optional chaining:
function getId(user, fallback) { return user?.id ?? fallback; }