Skip to content

Instantly share code, notes, and snippets.

@AliceWonderland
Forked from anonymous/3.4 Truthy.js
Created April 6, 2017 04:37
Show Gist options
  • Select an option

  • Save AliceWonderland/528b3a3f562c860dbd9876f7d15d0058 to your computer and use it in GitHub Desktop.

Select an option

Save AliceWonderland/528b3a3f562c860dbd9876f7d15d0058 to your computer and use it in GitHub Desktop.
3.4 Truthy created by smillaraaq - https://repl.it/GxZN/6
function isTruthy(arg){
var theType= typeof arg;
var theBool= !!arg; //the original bool of the param
var theMessage= "";
console.log(theType+" "+theBool);
if(theType==="undefined"){
theMessage= theType+" is falsey";
}else if(theType==="null"){
theMessage= "The "+theType+" value is falsey";
}else if(theType==="boolean"){
var theBoolMessage=theBool?"truthy":"falsey";
theMessage= "The "+theType+" value"+theBool+" is "+ theBoolMessage;
}else if(theType==="number"){
if(theBool){
theMessage= "The "+theType+" "+arg+" is truthy";
}else{
theMessage= "The "+theType+" "+arg+" is falsey (the only falsey number)";
}
}else if(theType==="string"){
if(theBool){
theMessage= "The "+theType+" is "+ theBoolMessage;
}else{
theMessage= "The empty "+theType+" is falsey (the only falsey string)";
}
}else{
theMessage="do nothing";
}
console.log(theMessage);
}
isTruthy(0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment