I find this syntax lengthy. Is there a shorter syntax like inspiring from null coalescing ?
let a = [];
console.log(a.length>0?a[0]:null);
Better way using
Optional_chaining
The optional chaining operator (?.) enables you to read the value of a property located deep within a chain of connected objects without having to check that each reference in the chain is valid.
The nullish coalescing operator (??) is a logical operator that returns its right-hand side operand when its left-hand side operand is null or undefined, and otherwise returns its left-hand side operand.
let a = [];
a.push("foo");
// long
console.log(a.length>0 ? a[0] : null);
// short
console.log(a[0] ?? null)