function negative($value){ return typeof $value==='boolean'? !$value: +!$value; }; console.log( negative(1), negative(0), negative(true), negative(false) );