Typing explained
Now we understand some basic types, we need to cover typing and how languages, particularly PowerShell, manipulate the type of the object in the variable. How does a computer know what type of object it is? Languages can be divided into those that only support static typing, where the object type the variable can hold is declared when the variable is created and doesn’t change, and those that support dynamic typing, where the contents of the variable determine what the type is. In dynamically typed languages, the type of the variable can change. Try the following:
$MyVariable = 'some stuff' $MyVariable | Get-Member $MyVariable = 42 $MyVariable | Get-Member
We can see that the object type of $MyVariable
changes depending on what is inside it, making PowerShell a dynamically typed language. In fact, PowerShell is described as Type-Promiscuous by Bruce Payette in PowerShell in Action, because it will try to make the thing that we put in a variable...