title: Object-Property assigned $null does not test true for $null
body: <p>I've started using PowerShell to get some things done and played with the variable <code>$null</code> in PowerShell.</p>
  <p>I've encountered the problem that when I assign the variable <code>$null</code> to a variable defined in a class, the test returns <code>false</code> not <code>true</code>.</p>
  <p>Example Code:</p>
  <pre><code>class test {
      [string]$test1
  }
  
  $test = [test]::new()
  
  $test.test1 = $null
  
  $null -eq $test2 # tests true
  
  $null -eq $test.test1 # tests false
  </code></pre>
  <p>Now the test of the undefinded variable <code>$test2</code> returns <code>true</code> as every undefined variable in PowerShell is assigned <code>$null</code>.</p>
  <p>But if I test the property <code>test1</code> of the object <code>test</code> which I assigned <code>$null</code> tests <code>false</code> for <code>$null</code></p>
  <p>Is it because in PowerShell <code>$null</code> is an object with the value <code>$null</code> and now the property of the object is not <code>$null</code> as it has the object <code>$null</code> assigned to it with an empty value?</p>
  <p>I've read into the docs of Microsoft <a href="https://docs.microsoft.com/en-us/powershell/scripting/learn/deep-dives/everything-about-null?view=powershell-7.1" rel="nofollow noreferrer">&quot;Everything you wanted to know about $null&quot;</a>, but it does not enlighten me.</p>
  <p>If I do not initialize the variable, then it will test <code>true</code> for <code>$null</code>.</p>