4 ms·
Recently wanted to convert a string of '0' or '1' to a native boolean, shortcut value = !!~~value;
by xhrpost 13y ago
Recently wanted to convert a string of '0' or '1' to a native boolean, shortcut
value = !!~~value;
- bpicolo 13y agojsPerf shows !!parseInt(str) and parseInt(str)? true : false as being decently faster...assuming I used jsperf properly. http://jsperf.com/test-bool-cast http://jsperf.com/test-bool-cast