Jump to content

comparing 2 variable values


Destramic

Recommended Posts

That should work fine.

 

 

// http://jsfiddle.net/qcr1qws4/

var first  = "Thomas";
var second = "Jack";

if (first == second)
    alert("Same Name");

if (first == "Thomas")
    alert("First person's name is Thomas.");

I'm confused what you mean by "comparing" two variables since that's what you did yourself in the main post. Also you should use tripple '=' operator, not double, if you want to be sure the two values are actually the same, because then it makes sure the type of the variable is the same as well. For instance a string of "1" and an integer of 1 would be "the same" when using double '=' operator.

 

Example:

 

 

var first = "1";
var second = 1;
 
console.log(first == second); //true
console.log(first === second); //false, different types.

 

But could you please elaborate more what you mean by "comparing" two variables ? Because like I said, it looks like you did it yourself in the main post.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.