0

Trying to understand why the following code block returns different results.

$item1 = "bill"
$item2 = "bill"

# This returns "Values are the same"
if ($item1 -eq $item2) {
    echo "Values are the same"
}
else {
    echo "Values are NOT the same"
}

# This returns "Values are NOT same"
function compare_items($i1, $i2)
{
    if ($i1 -eq $i2) {
        echo "Values are the same"
    }
    else {
        echo "Values are NOT the same"
    }
}

compare_items($item1, $item2)

I would think both return the same result as values being the same. I've tried type casting the variables as [string] and still getting same mismatch of results.

Mathias R. Jessen
  • 157,619
  • 12
  • 148
  • 206
  • You are passing the arguments incorrectly. You don't need parenthesis and the arguments should be space delimited. See the linked duplicate. Should be `compare_items $item1 $item2` – Doug Maurer Jun 18 '23 at 16:47
  • 1
    "set-strictmode -version latest" would catch this. "The function or command was called as if it were a method. Parameters should be separated by spaces." It's a common point of confusion. – js2010 Jun 18 '23 at 17:40

0 Answers0