Monday, 16 January 2012

JavaScript Intro

JavaScript Intro

JavaScript

JavaScript was formalized in the ECMAScript language standard and is primarily used in the form of client-side JavaScript, implemented as part of a Web browser in order to provide enhanced user interfaces and dynamic websites. This enables programmatic access to computational objects within a host environment

History

• JavaScript was originally developed by Brendan Eich of Netscape

• under the name Mocha,

• which was later renamed to LiveScript,

• and finally to JavaScript.

• LiveScript was the official name for the language when it first shipped in beta releases of Netscape Navigator 2.0 in September 1995, but it was renamed JavaScript in a joint announcement with Sun Microsystems on December 4, 1995, when it was deployed in the Netscape browser version 2.0B3.

What is JavaScript?

JavaScript is a

prototype-based scripting language

that is dynamic,

weakly typed

and has first-class functions.

It is a multi-paradigm language,

supporting object-oriented,

imperative,

and functional programming styles.

first-class functions

it treats functions as first-class objects. Specifically, this means that the language supports passing functions as arguments to other functions, returning them as the values from other functions, and assigning them to variables or storing them in data structures

function doOperation(params){

//do something

}

var doOperation = function(params){

//do something

}

Prototype-based

is a style of object-oriented programming in which classes are not present, And behavior reuse (known as inheritance in class-based languages) is performed via a process of cloning existing objects that serve as prototypes. This model can also be known as classless, prototype-oriented or instance-based programming. Delegation is the language feature that supports prototype-based programming.

function employee(name,jobtitle,born){

this.name=name;

this.jobtitle=jobtitle;

this.born=born;

}

Using above constructor we can use classes like

var fred=new employee(“Ranga",“SE",1988);

Can easily add new attributes to newly created object

employee.prototype.salary=null;

fred.salary=200000;

document.write(fred.salary);.

Dynamic

high-level programming languages that execute at runtime many common behaviors that other languages might perform during compilation

weakly typed

var x = false;

alert(x);

x = "test String";

alert(x);

x = 5;

alert(x);

multi-paradigm language

Paradigms differ in the concepts and abstractions used to represent the elements of a program (such as objects, functions, variables, constraints, etc.) and the steps that compose a computation (assignment, evaluation, continuations, data flows, etc.).

supporting object-oriented

(OOP) is a programming paradigm using "objects" – data structures consisting of data fields and methods together with their interactions – to design applications and computer programs. Programming techniques may include features such as data abstraction, encapsulation, messaging, modularity, polymorphism, and inheritance. Many modern programming languages now support OOP, at least as an option.

Imperative

is a programming paradigm that describes computation in terms of statements that change a program state. In much the same way that imperative mood in natural languages expresses commands to take action, imperative programs define sequences of commands for the computer to perform.

functional programming styles

is a programming paradigm that treats computation as the evaluation of mathematical functions and avoids state and mutable data. It emphasizes the application of functions, in contrast to the imperative programming style, which emphasizes changes in state.


No comments: