Turn on Specific Axis Constraints - Keeping Others Selected (JS)

I have a button that turns axis constraints positions X and Z on and off. Here’s the script (JavaScript):

var toggle = false;

function Toggle () {
	toggle = !toggle;
	if (toggle) {
		GetComponent.<Rigidbody>().constraints = RigidbodyConstraints.FreezePositionX | RigidbodyConstraints.FreezePositionZ;
	}else{
		GetComponent.<Rigidbody>().constraints &= ~RigidbodyConstraints.FreezePositionX;
		GetComponent.<Rigidbody>().constraints &= ~RigidbodyConstraints.FreezePositionZ;
	}
}

If I turn it on, and other constraints are selected, it turns them off and keeps X and Z on.
If I turn it off, and other constraints are selected, only X and Z turn off - like it’s supposed to.

if statement isn’t working the way I want it to.
else statement is working correctly.

I don’t understand what I need to do to turn on X and Z while other constraints are on WITHOUT turning them off.

(I’ve looked all over the internet for this, and I can’t find a proper solution. I did find this, which helped me with the else statement, but I don’t understand the logic enough to apply it to the if statement: " Can you unfreeze a rigidbody.constraint position as you can freeze them? - Questions & Answers - Unity Discussions ").

I’d really appreciate someone to point out my mistake and help me understand this logic. Thank you so much in advance!

function Toggle () {
toggle = !toggle;
if (toggle) {
GetComponent.().constraints |= RigidbodyConstraints.FreezePositionX;
GetComponent.().constraints |= RigidbodyConstraints.FreezePositionZ;
}else{
GetComponent.().constraints &= ~RigidbodyConstraints.FreezePositionX;
GetComponent.().constraints &= ~RigidbodyConstraints.FreezePositionZ;
}
}

The main bit being the |= on the if statement.