Trying to determine the truthiness or falsiness of an object is proving to be a challenge for me. If an object contains all truthy values, I want one outcome; if it contains falsy values such as 0, an empty string, or undefined, I want a different outcome. However, my current approach always executes the first part of the if statement. Am I missing something here?
class Truthy {
a: string;
b: number;
c: object;
constructor() {
this.a = 'a';
this.b = 1;
this.c = {};
}
}
class Falsely {
a: string;
b: number;
c: object;
constructor() {
this.a = '';
this.b = 0;
this.c = undefined;
}
}
const truthy = new Truthy()
const falsely = new Falsely()
if (!!truthy) {
// do something
} else {
// do something else
}
if (!!falsely) {
// do something
} else {
// do something else
}