Is it possible to use ternary operator for console.log?


I thought this would be something simple to do, but I don’t think it’s possible, why is that?

This is what I’m trying to do.

console.log("hello") ? bool : "";

This gives me an error: Expected an assignment or function call and instead saw an expression. Not sure exactly what that means.

>Solution :

Yes. you have to evaluate the expression at runtime.
Do I like this.

const someBool = true;

Leave a ReplyCancel reply