Skip to content

Instantly share code, notes, and snippets.

@scriptschat
Created September 24, 2020 11:47
Show Gist options
  • Save scriptschat/3dca59c2bd877a16f6158dd706c2c5bf to your computer and use it in GitHub Desktop.
Save scriptschat/3dca59c2bd877a16f6158dd706c2c5bf to your computer and use it in GitHub Desktop.
converting various values to boolean and verify how JavaScript behaves.
//if you try following line of code in chrome console
var a = new Boolean(undefined);
console.log(a);
//false
a = new Boolean(null);
console.log(a);
//false;
a = new Boolean(0);
console.log(a);
//false
a = new Boolean('0');
console.log(a);
//false
a = new Boolean(false);
console.log(a);
//false;
a = new Boolean('false');
console.log(a);
//true
a = new Boolean(NaN);
console.log(a);
//false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment