Can you explain this equation?

JavascriptOperators

== and != are called comparison operators. They are used to compare two values and see whether they are the same (==) or check if they are different (!=). E.g.

if (gender=="Male") alert("You are a man.");
 = is used to assign a value to a variable. E.g.
myFavouriteNumber=5;

 To Sum it up…

An = sign is used to assign a value to a variable: e.g.

var a=3;
a=5+2;

An == sign is used to compare if two values are equal e.g.

if (a==3) {
    alert("a is equal to 3");
} else {
    alert("a is not equal to 3");
}

A != sign is used to compare if two values are different e.g.

if (a!=3) {
    alert("a is not equal to 3");
 } else {
     alert("a is equal to 3");
 }

 

Did you like this challenge?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate this post.

As you found this challenge interesting...

Follow us on social media!

Tagged with: ,