PowerShell Datatype Declaration

PowerShell is a scripting and not a programming language, that much I know. Sometimes I am still missing a strict(er) datatype declaration to prevent a lot of mistakes caused by none or (automatically) false declared variables.

Have a look at the examples below and let me know what you think of it đŸ™‚

1
2
3
4
2+"5" # => 7 
"2"+5 # => 25
[int]"2"+5 # => 7
[string]2+"5" # => 25

In my opinion all of the above examples should throw an error while the following ones should not:

1
2
3
4
2+5 # => 7
"2"+"5" # => 25
[int]2+5 # => 7
[string]"2"+"5" # => 25

Leave a Reply

Your email address will not be published. Required fields are marked *