## The Null-Coalescing Operator

### A closer look at the null-coalescing operator and how it can help us in writing smarter, more concise scripts.

Today we take a closer look at the null-coalescing operator and how it can help us in writing smarter, more concise scripts. PS> $userDate ?? (Get-Date -Format "yyyy-MM-dd") 2021-02-14 PS>$userDate = Get-Date -Year 2020 -Format "yyyy-MM-dd" PS> $userDate ?? (Get-Date -Format "yyyy-MM-dd") 2020-02-14 How it works We can write some simple code to visualize what the null-coalescing operator is doing function nullCoalescingOperator ($leftValue, $rightValue) { if ($null -eq $leftValue) { return$rightValue } else { return \$leftValue } } Usually we will want to assign the resulting value to a variable. [Read More]