Jump to content

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.