Monday, March 9, 2009

JavaScript Fundas: null, undefined, nan, false

What does ==, ===, false, undefined and nan mean in Javascript?

Comparison via ==

== indicates Equality, regardless of type.

Comparison via ===

=== indicates identity, types must match.

Pitfalls using comparison
For boolean operations it evaluates to false. Use === when comparing to the number 0.

var x = 0;
var y = false;

x == y → true
x === y → false


"" (empty string)

Evaluates to false in boolean operations. Use === when comparing to an empty string.

var x = "";
var y = false;

x == y → true
x === y → false


null

Evaluates to false in boolean operations. Use === when comparing to null.

var x = null;
var y = false;

x == y → true
x === y → false


undefined

If a variable hasn't been declared or assigned yet (e.g: an argument to a function which never received a value, an object property that hasn't been assigned a value) then that variable will be given a special undefined value.

Evaluates to false in boolean operations. Always use === when comparing to undefined.

var x;
var y = false;

typeof(x) → undefined (as a string)

x == y → true
x === y → false


NaN

Not a Number, generated when arithmetic operations return invalid results.

Evaluates to false in boolean operations. Always use isNaN() when comparing to NaN.

var x = 10/seventeen;

x → NaN

NOTE: NaN is never equal to itself!

var x = 10/seventeen;

x == x → false


Courtesy: http://www.hunlock.com/blogs/Essential_Javascript_--_A_Javascript_Tutorial
This is a very good JavaScript site. Many of my misconceptions were cleared when I went thru this site.

Hope these concepts help you!

Wednesday, March 4, 2009

Microsoft MVP Summit at Redmond USA

MVPs constitute a select community of independent technical experts committed to sharing their knowledge with others and the company. Microsoft presents the MVP Award to appraise the individuals for their exceptional contributions to technical communities worldwide. Microsoft considers these people as the representatives of the user's voice. The MVP punch line "Independent Experts. Real World Answers" tolds very true with these people :)

About 1,500 Microsoft Most Valuable Professionals (MVPs) have converged on Microsoft’s Redmond, campus this week for the 2009 MVP Global Summit. It has been four days of networking and discussions with product groups, executives and others.

You can find MVP awardees here