Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

JS Convert function to one line without if/else

How to convert this function without using if/else?

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

}

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading