This:

console?.log('YES');

Becomes:

if (typeof console !== "undefined" && console !== null) {
console.log('YES');
}