How to convert this function without using if/else?
function Menu() {
if (!currentUser || currentUser.getValue == 7) {
return false
} else {
return true
}
}
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.
It's
let showMenu = (!p.currentUser || p.currentUser.getValue('id') === 7) ? false : true;
If you want to use promises you can
function validateMenu() {
return new Promises((resolve, reject) => {
if (!p.currentUser || p.currentUser.getValue('id') === 7) {
resolve(false)
} else {
resolve(true)
}
});
}
You don't need if...else statement or conditional (ternary) operator, you could just use arrow function expression and logical operators:
const Menu = () => !!currentUser && currentUser.getValue('id') !== 7;