0

Is there a way in PowerShell to do a simple short-circuit evaluation for a variable to take first value or second, if first is empty ?

Like in JS:

let x = '';
let y = '1';
let z = x || y; // '1'
  • Check the answer in https://stackoverflow.com/questions/10623907/null-coalescing-in-powershell/17647824 – junkangli Apr 13 '21 at 08:45
  • If understand correctly, this is a short-circuit evaluation, but specifically meant to be used with the `$null` value only ? If it is an empty string, there is no way to do it, yet ? – Aleksandar Ivanov Apr 13 '21 at 09:15
  • @AleksandarIvanov not with a single binary/short-circuit operator. `$c = if(-not $a){$b}else{$a}` – Mathias R. Jessen Apr 13 '21 at 11:53

0 Answers0