mardi 20 novembre 2018

What is better conditional expressions or a if statement?

I was reading an article that was talking about conditional javascript but they didn't explain which was better to use. I made a fiddle with the 2 examples.

console.log('start');

const VALUE = true;
const TEST = false;

//test 1
VALUE && !TEST && (() => {
    console.log('hello there!');
})();

//test 2
if(VALUE && !TEST) {
    console.log('bye');
}

https://jsfiddle.net/xvdLq6to

The most important thing with this example is that I don't want to call a new function I want to execute the code in the function its inside just like an if statement. If you know something better then I can't wait to hear that!

Aucun commentaire:

Enregistrer un commentaire