Mixing operand types: the type of the left operand dictates the behavior

suggest change

For Addition

"4" + 2         # Gives "42"
4 + "2"         # Gives 6
1,2,3 + "Hello" # Gives 1,2,3,"Hello"
"Hello" + 1,2,3 # Gives "Hello1 2 3"

For Multiplication

"3" * 2   # Gives "33"
2 * "3"   # Gives 6
1,2,3 * 2 # Gives 1,2,3,1,2,3
2 * 1,2,3 # Gives an error op_Multiply is missing

The same rule affects comparison operators. Read-Host returns a string, so -gt compares text and "33" is not greater than "5":

$a = Read-Host "Enter a number"
Enter a number : 33
$a -gt 5
False

Feedback about page:

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



Table Of Contents