Switch 0 and 1

by moob

JavaScript

var x = 1;

//switch via simple maths
x = 1 - x;
console.log(x);

//better, switch using eXclusive Or (xor)
console.log(x ^ 1);