文字列のパースで 無いかもしれないものがいくつかある場合 正規表現で「?」をつけて match させてから結果を if 文で色々処理するのってわかりづらいし let 多用になるのがいまいち
「?」つけずにそれぞれのパターンで match させてパターンごとに処理をさせたほうがわかりやすいかも

こういう関数を用意して

const match = (str, patterns) => {
for(const [cond, fn] of patterns) {
if (cond == null) return fn()
const matched = cond instanceof RegExp ? cond.exec(str) : str.match(cond)
if (matched) return fn(matched, ...matched)
}
}

こう使う

const tes = str => {
const result = match(str, [
[/^(\d+)$/, (_, __, d) => [+d, +d]],
[/^(\d+),$/, (_, __, d) => [+d, null]],
[/^,(\d+)$/, (_, __, d) => [null, +d]],
[/^(\d+),(\d+)$/, (_, __, d1, d2) => [+d1, +d2]],
[null, () => [null, null]],
])
console.log(result)
}

tes("10,20") // [10, 20]
tes("30,") // [30, null]
tes(",40") // [null, 40]
tes("50") // [50, 50]
tes("") // [null, null]

見やすさはイマイチかも