The problem with JavaScript…

function myTest() {
var a = 123;

var b = 123;
a = "123";
return (a == b);

This obviously is going to return false. Or is it true?

It actually depends on the browser you're working with (thank you, Vítor, for pointing this out to me).

The way I see it, it makes no sense to use comparison operators diferently typed variables.

The problem is, of course the fact that JavaScript is a not a "strongly typed programming language" but I think it would be great to be able to declare strongly typed variables in JS. Somewhat of a mid-term solution…

If you would declare var something; that would be a generic variable, to mantain backward compatibility, but if you declared int x; float y; String z = new String("test"); the browser would enforce type validation and averyone would be happier 😛

Having said that, I guess there are some arguments for the "weakly typed" option, but for me, I can't see any real advantages…

In the meanwhile, maybe this or this will share some light…

The problematic operators are the relational operators ('==', '', '') and the concatenation operator ('+') which is also used for addition. All these operators work with more than one type.


1 Response to “The problem with JavaScript…”

  1. 1 Vítor Ferreira November 9, 2005 at 6:54 pm

    n percebes nada disso

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow me on Twitter


For what it’s worth…

My blog is worth $1,693.62.
How much is your blog worth?

Blog Stats

  • 5,845 hits

%d bloggers like this: