Loose Typing in Javascript

What is Loose Typing?

Well, this seems like a good place to start. It is important to understand both what loose typing is, and what loose typing is not. Loose typing means that variables are declared without a type. This is in contrast to strongly typed languages that require typed declarations.

Consider the following examples:

  1. /* JavaScript Example (loose typing) */  
  2. var a = 13; // Number declaration  
  3. var b = “thirteen”; // String declaration  
  4.   
  5. /* Java Example (strong typing) */  
  6. int a = 13; // int declaration  
  7. String b = “thirteen”; // String declaration  

Notice that in the JavaScript example, both a and b are declared as type var. Please note, however, that this does not mean that they do not have a type, or even that they are of type “var”. Variables in JavaScript are typed, but that type is determined internally. In the above example, var a will be type Number and var b will be type String. These are two out of the three primitives in JavaScript, the third being Boolean.

Source: http://blog.jeremymartin.name/2008/03/understanding-loose-typing-in.html

Advertisements

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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