I am trying to find a way to cast an expression such as a condition statement to a string without having the expression being processed.
I tried using the .toString() method on the 'condition' parameter in the following 'assert' function.
const config = {
usernme: 'username1',
password: 'password1'
}
function assert(condition, message) {
if (!condition) {
message = message || `Assertion failed: ${condition.toString()}`;
if (typeof Error !== "undefined") {
throw new Error(message);
}
throw message; // Fallback
}
}
assert('username' in config);
Actual error message: Assertion failed: false
Anticipated error message: Assertion failed: 'username' in config