As far as I’m aware Twig supports all of the standard logical operators ==, !=, <, >, >=, and <=. Also, your first example {% if var1 = var2 %} does not check for equality, it assigns var2 to var1, you might want to change it to the comparison operator ==.
The Twig sameas built in test, is essentially a strict type comparison operator ===, hence why they both need to be strings in your example.