JS Convert function to one line without if/else

Advertisements

How to convert this function without using if/else?

function Menu() {
if (!currentUser || currentUser.getValue == 7)  {
    return false
} else {
    return true
}

}

>Solution :

Maybe just do ?

function validateMenu() {
  return p.currentUser && p.currentUser.getValue('id') !== 7
}

I really don’t understand why would you want to use a callback or a Promise for this case. There is nothing asynchronous involved, only two simple conditions being checked.

You might want to read a bit more about callbacks and Promises.

Leave a ReplyCancel reply