Skip to content

Instantly share code, notes, and snippets.

@rintoandrews90
Created September 4, 2019 16:38
Show Gist options
  • Save rintoandrews90/df9f31eb1bb47b4cae1f40841b4a96f1 to your computer and use it in GitHub Desktop.
Save rintoandrews90/df9f31eb1bb47b4cae1f40841b4a96f1 to your computer and use it in GitHub Desktop.
/**********************
* Truthy & falsy values
***/
// falsy values : undefined, null, 0, '', NaN
// truthy valyes: not falsy values
var height;
if (height || height === 0 ) {
console.log('value defined');
} else {
console.log('undefined');
}
var txt = '';
if (txt || txt === 0 ) {
console.log('value defined');
} else {
console.log('undefined str');
}
// string '23' converted to int so its true
var age = 23;
if (age == '23') {
console.log('true');
}
// string '23' will not be converted to int so its false
if (age === '23') {
console.log('true');
}else{
console.log('false')
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment