Introduce a new conceptual topic that explains to-Boolean coercion logic ("truthiness") #3356
Labels
issue-doc-idea
Issue - request for new content
Pri3
Priority - Low
up-for-grabs
Tag - issue is open for any contributor to resolve
PowerShell can treat any type implicitly as a Boolean, which is generally very handy, but can be problematic if the rules aren't clear.
The rules are summarized below, and I hope they'll become the basis for a new conceptual topic such as
about_Booleans
.The following topics should then be updated to point to the new topic:
about_If
about_While
about_Do
about_Arrays
(the section about the.Where()
method)Where-Object
To-Boolean conversion summary:
The following are implicitly
$false
:''
/""
(empty string)$null
0
(of any numeric type).Pitfall: Any non-empty string evaluates to
$true
[bool] 'False'
is$true
[bool]::Parse('false')
does return$false
(and$true
for'true'
, but recognizes nothing else).Instances of any other (non-collection) type are implicitly
$true
, including of type[pscustomobject]
.IList
interface - see the source code):$false
, as is the special "null collection" value indicating the absence of output from a command,[System.Management.Automation.Internal.AutomationNull]::Value
.$true
.The text was updated successfully, but these errors were encountered: