Why does this code display 31 instead of 4 in the console?

Because "3" and "1" are string valuesBecause the expression subtracts the numbers

It displays 31 because "3" and "1" are string values, not numbers.