Sample code below. Notice that $n in some ways acts like $null, but not when added to an array.
$n -eq $null, and $c -eq $n, yet they behave differently when added to an array.
How can you tell if the value of the variable is nothing vs. $null? (without adding it to an array)
How can you create a variable whose value is nothing? (Without using the get-nothing function?)
# $n is nothing .. it is defined, yet has no value, not even $null
function Get-Nothing
{
write-host "Returns Nothing"
}
$n = Get-Nothing
$na = @($n)
Write-Host "N type is ($($n.gettype()))" # "You cannot call a method on a null-valued expression."
Write-Host "NA is $($na.gettype()), count=$($na.count)" # count == 0
Write-host "N is Null? $($null -eq $n)" # true
# $c is $null.
$c = $null
$ca = @($c)
Write-Host "C type is ($($c.gettype()))" # "You cannot call a method on a null-valued expression."
Write-Host "CA is $($ca.gettype()), count=$($ca.count)" # count == 1
Write-host "C is Null? $($null -eq $c)" # true
Write-Host "C == N ? $($c -eq $n)" # true
$a = 1,2,3
$ac = $a + $c
$an = $a + $n
Write-Host "AC count=$($ac.count)" # Count == 4
Write-Host "AN count=$($an.count)" # Count == 3