I am trying to do conditional check using ternary operator in nodejs.
The ternary operator is working fine without issues in below scenario. It prints text in console
{true ? (
console.log("I am true")
) : (
console.log("I am not true")
)}
And the same is not working under below scenario and it throws following error
let text = "I am true";
^^^^SyntaxError: Unexpected identifier
{true ? (
let text = "I am true";
console.log(text);
) : (
console.log("I am not true")
)}
I am unable to understand why this is behaving differently.