samedi 25 avril 2020

Is shortened if conditions possible

We know that you can shorten an if statement by typing

(condition) ? true : false;

But is it also possible to check 2 variables if there both an i.e. string:

var string1 = "text"
var string2 = "text"

if(string1 && string2 == "text") {
    // Anything else
}

I personally don't think because it will check if string1 exists and that string2 is "text". But maybe I'm wrong

Aucun commentaire:

Enregistrer un commentaire