Scope

suggest change

The default scope of a variable is the current scope. At the prompt, that scope is Global. Inside a script, the top-level scope is script scope, not global, so run this sample at the prompt. A scope modifier is a prefix on the variable name, $scope:varname:

$foo = "Global Scope"
function myFunc {
    $foo = "Function (local) scope"
    Write-Host $global:foo
    Write-Host $local:foo
    Write-Host $foo
}
myFunc
Write-Host $local:foo
Write-Host $foo
Global Scope
Function (local) scope
Function (local) scope
Global Scope
Global Scope

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents