Javascript: Awesomeness

I have been working with Javascript for over a year now and have been using it as language to manipulate the DOM. I had never taken Javascript seriously enough or thought of it to be a real language till a few months back when I had to start working with Orbited.

Recently I went back to understand the basics of Javascript and I decided to go through some of the things that I found were really awesome. Now most of this stuff may be lame for experienced programmers but I hope this helps someone who starting off.


I knew that Javascript had primitives and Object types. So going through a small example here

var s = "Mary had a little lamb";
alert(typeof s); // This would display 'string'

var ss = new String("Bazingaa");
alert(typeof ss); // This would display 'Object'

If you notice, without really having the need to define an object javascript still lets you call methods on primitives types. For example

 var s = "Soft Kitty";
alert(s.length); // 10

Javascript creates transient objects for all primitives types so that methods may be called upon them and destroys them when no longer needed. (How cool is that!).

So now the question is are strings passed by reference or by value, because all primitives types are passed by value and Objects passed by reference. The answer is, its hard to tell, but it doesn’t matter as strings are immutable so basically you cannot change the value stored in them and when you do you are in fact creating a new object.

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 )

Connecting to %s