Tag Archives: compare

JavaScript Comparision Snippet

== vs. ===

I know this is really for beginners, but have you ever asked yourself what are the differences between == and === when comparing in JavaScript, and when to use it? Here’s an example:

var a = false;
alert(a === 0); // prints false

That’s false. Even when both the zero and the variable are faulty the entire operation is false. Because the 0 is a number and the variable a is boolean, therefore their different types give us the answer. If there was a comparision only with == the result would be true:

var a = false;
alert(a == 0); // prints true

It’s good when you expect some variable to match certain type to compare with ===. So the correct code is:

var a = false;
alert(a === false); // prints true

Here the type of a compares with boolean. See the complete demo.

Flex 3: compare two dates

Theory of Operation

You’re using Flex 3 and want to compare two dates. The format of the dates is string something like “2009 May 05”. The question is …

What’s the best way to compare them

Well if you’ve the dates as strings and you can easily conver them to something like unix timestamps. If they are a Date object you can try lik so: Continue reading Flex 3: compare two dates