A Deeper Look Into Javascript – Part I

Javascript has been around since the early days of Web and is already embedded into the millions of web pages for performing client(browser) side actions.But because of some reason it was never taken too seriously in the initial days compared to the languages that were used for server side programming.Back in 2000 when I started my programming career, Javascript was a language that you need not learn much , use it for some validations, copy/paste as much as you can….With the gradual advent of Web 2.0 concept and AJAX as a technology it was very clear that you cannot neglect javascript and it is here to stay, as we need more interactive and responsive web applications.

The “Java” in javascript is really a misnomer and misguiding.Javascript has absolutely nothing to do with Java.It was developed by Netscape as “LiveScript” and was later renamed to javascript.Later javascript was standardized by ECMA.The greatest power of Javascript is it’s simplicity and ease of use.Along with this it has the following powerful language features:

  • Object Oriented Prototype Based – Javascript is an object oriented language but differs from other OO languages like C# or Java in the fact that it does support class based object orientation.In class based object orientation we have classes defining the attributes and behavior and objects are unique instances of those classes.In prototype based languages there is no notion of classes, everything is an object.For reuse/inheritance we need to create copy of an existing object and alter it’s properties and behavior.This is very flexible as compared to class based inheritance where you might end up designing a rigid class hierarchy.
  • Dynamic – Javascript is a dynamically typed language and type of the variables are determined at runtime based on value it is holding.
  • Functional – Javascript treats functions as objects and supports higher order functions,anonymous methods and closures.
  • Imperative and Structured – Javascript allows to write programs in imperative and procedural style as well.

Javascript needs a runtime to execute and interact with HTML DOM.This is where the javascript engines embedded in the browsers come into picture.Initially these were not much efficient and error prone.But over time the javascript engines have improved.Lately the interest and enthusiasm shown by the OEMs for improving javascript performance in their browsers is a positive sign.May be we will see lots of improvement in recent times.The javascript engines of the major browsers are listed below:

  • Chrome V8 Javascript Engine – V8 is a high performance javascript engine which compiles javascript source directly to machine code bypassing any byte code or intermediate interpreter.V8 promises faster property access using a class transition technique,direct machine code generation and a generational garbage collection.
  • Firefox SpiderMonkey – SpiderMonkey provides a compiler which compiles javascript source to byte code, interpreter which consumes the byte code and a mark and sweep garbage collector.
  • IE JScript Engine – This has a byte code interpreter with a mark and sweep garbage collector.
  • Safari Nitro – Safari’s Nitro is based on WebKit’s SquirrelFish. It is a high performance byte code interpreter.SquirrelFish Extreme comes with byte code optimizations, Context Threading, a property cache, and a regular expression JIT.

This is good to start with.Next post onwards we start exploring the individual language features of javascript.

This entry was posted in Programming & Languages. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *