lundi 21 décembre 2020

IF ELSE using ternary operator [duplicate]

I am using the ternary operator as my if else condition. However, I am getting the not defined error using it. Here's my sample code below.

let a = 'apple'

let res = b ? b : a
console.log(res)

From what I know it will check the variable b if it has value and since it is not defined it should go to else and display the word apple?

But using the code above gives b is not defined error.

Aucun commentaire:

Enregistrer un commentaire