I want to know why some of my variables are working although they are not declared as global For an example:
Function B {
#Some code..
if ($var1 -eq 'true') {
Do something
}
}
Function A {
$var1 = 'false'
$var2 = 'false'
#Some code..
if ($a -eq "1") {
$var1 = 'true'
}
#Call function B
Function B
}
There are more functions in my code but the variables we not be exposed unless I will do this: So I am wondering why in the case above its working. I have many cases that its not working without declaring the variable as global
Set-Variable -Name "varname" -Value $varname -Scope global
How function B supposed to get the changes of $var1 when it changed in function A?