In javascript I have an if statement and I want to log the first condition that defaulted to true. For instance if a === true then I want to console.log a (update: e.g., “a” or “b” or “c”, the actual character).
Any ideas?
if(a || b || c){ console.log(this) }
Thanks guys!
The best thing to do is, of course, use a debugger and inspect
a,b, and/orcwhen you branch into theifstatement’s body. 🙂Doing it in code,
there’s no shortcut if you’re really trying to see “a”, “b”, or “c”update what was I thinking? Of course there’s a shortcut:Or if you want to see the value as well:
Live example | Live source
Original longer version:
Or (and this is quite tricky and much longer, so not recommended):
…which works because
switchstatementcases are evaluated at runtime, and in order.