Simple js arrow funtion and ternary operator question

What I’m doing wrong with my atempt to use an arrow function here?

function setup() {
  createCanvas(400, 400);
  const x = 0;
  const y = 10;
  const t1 = x > y ? x : () => console.log("nono from arrow");
  const t2 = x > y ? x : nono();
}

function nono() {
  console.log("nono from func");
}

//this code logs: 'nono from func' 

thanks

On the statement above you’re conditionally creating/defining a function.

And on the 1 above you’re conditionally calling/invoking an already existing function.

Ok, that makes sense. Thanks.
So what I was looking to do was

 const t1 = x > y ? x : (() => console.log("nono from arrow"))();

//that logs: 
//nono from arrow 
//nono from func  

The so talked about self-invoking anonymous function at least! Great! thanks

2 Likes

Wrong again LoL
thanks :)))