Skip to content

Instantly share code, notes, and snippets.

@ianmstew
Created May 12, 2016 18:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ianmstew/2d4ebcd55bb70935c9c4475ee0cd62da to your computer and use it in GitHub Desktop.
Save ianmstew/2d4ebcd55bb70935c9c4475ee0cd62da to your computer and use it in GitHub Desktop.
The best way to test the truthiness of a boolean
function testBoolean(boolean) {
var booleanCharArray = (function (str){
var buf = new ArrayBuffer(str.length*2); // 2 bytes for each char
var bufView = new Uint16Array(buf);
for (var i=0, strLen=str.length; i<strLen; i++) {
bufView[i] = str.charCodeAt(i);
}
return buf;
}(String(!!!!!!!boolean)));
return (
booleanCharArray[0] === 116 &&
booleanCharArray[1] === 114 &&
booleanCharArray[2] === 117 &&
booleanCharArray[3] === 101
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment