Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions simple javascript question

  • simple javascript question

    Posted by Fabio Apelbaum on June 10, 2016 at 8:21 pm

    Hi guys, quick question

    in my scripts I use a lot of statements with logical operators (this “OR” this):

    var b = "b"

    if(b == "a" || b == "b"){
    alert("I am a 'b'")
    }else{("I am not a 'b'");
    }
    //result is "I am a 'b'"

    Now, I was trying to do the same “OR” statement but with a != operator and it does not work… how do you do a if statement with OR operator when using !=


    //this does not seem to work
    var b = "b"

    if(b != "a" || b != "b"){
    alert("I am a 'b'")
    }else{ alert("I am not a 'b'");
    }
    //result is also "I am a 'b'

    Thanks for helping me clarifying this!

    Fabio

    Abdessalem Boukil replied 9 years, 11 months ago 3 Members · 2 Replies
  • 2 Replies
  • Dan Ebberts

    June 10, 2016 at 9:22 pm

    Try it this way:


    var b = "b"

    if(b != "a" && b != "b"){
    alert("I am not a 'b'")
    }else{
    alert("I am a 'b'");
    }

    Dan

  • Abdessalem Boukil

    June 10, 2016 at 9:50 pm

    The condition b != "a" || b != "b" will always return true and it will always output “I am a ‘b'” .
    To fix it you only should change b != "a" || b != "b" to b != "a" && b != "b"


    var b = "b"

    if(b != "a" && b != "b"){
    alert("I am a 'b'")
    }else{ alert("I am not a 'b'");
    }

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy