Undefined values: Difference between revisions

no edit summary
mNo edit summary
No edit summary
Line 959:
Result: 0
</lang>
 
=={{header|PowerShell}}==
The <code>Get-Variable</code> cmdlet gets the Windows PowerShell variables in the current console. Variables can be filtered by using the <code>-Name</code> parameter.
If a variable doesn't exist an error is returned. Using the <code>-ErrorAction SilentlyContinue</code> parameter suppresses the error message and returns <code>$false</code>.
<lang PowerShell>
if (Get-Variable -Name noSuchVariable -ErrorAction SilentlyContinue)
{
$true
}
else
{
$false
}
</lang>
{{Out}}
<pre>
False
</pre>
PowerShell represents things like the file system, registry, functions, variables, etc. with '''providers''' known as PS drives.
One of those PS drives is Variable. <code>Variable:</code> contains all of the variables that are currently stored in memory.
<lang PowerShell>
Get-PSProvider
</lang>
{{Out}}
<pre>
Name Capabilities Drives
---- ------------ ------
Registry ShouldProcess, Transactions {HKLM, HKCU}
Alias ShouldProcess {Alias}
Environment ShouldProcess {Env}
FileSystem Filter, ShouldProcess, Credentials {C, D, E, Q}
Function ShouldProcess {Function}
Variable ShouldProcess {Variable}
Certificate ShouldProcess {Cert}
WSMan Credentials {WSMan}
</pre>
To access the Variable PS drive you'd use the same syntax as you would with the file system by specifying <code>Variable:\</code>.
<lang PowerShell>
Test-Path Variable:\noSuchVariable
</lang>
{{Out}}
<pre>
False
</pre>
If a variable doesn't exist, it technically has a value of <code>$null</code>. <code>$null</code> is an automatic variable that represents "does not exist."
<lang PowerShell>
$noSuchVariable -eq $null
</lang>
{{Out}}
<pre>
True
</pre>
 
=={{header|Prolog}}==
308

edits