Friday, April 04, 2008


if (obj == null)
What do we expect to check by using the above condition in javascript?

javascript never sets a value to null. So we can check only whether we have assigned null programmatically by using the above condition. In most of the programming languages if we want to check whether a values has been assigned to a variable or not we can use the above condition(C# as an example) but not in javascript. When a value is not assigned to a variable in javascript, it assigns the default value of 'undefined'. So check undefined.

if(typeof obj == 'undefined')

Tuesday, April 01, 2008

?? Operator

I have been addicted to use ? operator in C# for sometime. If I want to check a condition and do something according to the true/false status of that condition we used this method in old days.

if (Request.QueryString["param1"] != null
param1 = Request.QueryString["param1"];
param1 =

After the introduction of the "?" operator I used to write the same piece of code as,
string param1 = Request.QueryString["param1"] != null ? Request.QueryString["param1"].ToString() : "";

C# has introduced another operator which is "??". It is used to replace null. So I'll kept in mind that to force myself to use "??" operator where I can use it as,

string param1 = Request.QueryString["param1"] ?? "";