Vous êtes sur la page 1sur 9

JavaScript JS is CASE SENSITIVE LANGUAGE. Brief History Javascript(JS) became popular when the Java Applets failed.

It became the language of the web. Its popularity as a programming language is completely independent of its qualities as a programming language. Its formally known as ECMAScript. JS has loose typing, functions, dynamic objects and has a very powerful object literal notation. It also has prototypal inheritance. All the top-level variables in Js are put into a global namespace called the global object. A sample testing code <html> <head> <script src=program.js> </script> </head> </html>

Now create another file program.js in the same folder and write your code for example: document.writeln(Hello world);

You can also write the above code as <html> <head> <script type=text/javascript> document.writeln(Hello world); </script> </head> </html> See that when you write the code in a different file with a .js extension WE DONt have to use the script tag <script>.

Grammer Name the names of the variables are same like cpp. can start with a alphabet or a digit or _ Numbers -Js has single number type. Numbers are represented as 64 bit floating type i.e. 1 and 1.0 are same in JS. On a less formal note theres no int/float type as in cpp.

Strings -Can be wrapped in single quote - \ is the escape character. All characters in Js are 16 bit wide ( supports Unicode ). JS doesnt has a character type i.e. no char type is there so if you want a character its equivalent to a string with one character.. Strings have a length property i.e. seven.length is 5. Strings are immutable i.e. they cant be changed but can be concatenated with +. Srings have methods For eg:

cat.toUpperCase() will change it to CAT. NOTE: When you want to put a string with double quotes inside a string you can use single quote for that . For example This is a test is valid This is a test will not be valid.

Expression type Simple expression can be string Number Built in value ( for eg NaN, false ) Operator precedence : . [] () refinement and invocation unary operators , division modification, modulo add/concatenate , subtract inequality operator equality operator

delete new typeof + - ! / * % + >= <= >< === !== && || logical and logical or

? ternary The above precedence is from highest to lowest i.e refinement ops have the highest precedence and ? has the lowest.

Description of the above :

typeof produces Number String Boolean Undefined Funcation Object For arrany and null type typeof produces object. var x=10; typeof(x) produces number coz this is a number type.

invocation
is a pair of () that follow the function value. they contain the arguments that will be deliverd to the function value. Refinement [ ] is used to specify the property or element of an object of an array.

Literals Convenient for specifying new objects.

Objects
an object is a container of properties. You can consider this as a structure or a class but without the public , private and protected access storage specifier. Property name can be a string or any string. property value can be any value except undefined. Objects in Js are class free. Objects can contain other objects. Js a prototype linkage that allows one object to inherit the properties of the other object. Prototype linkage can reduce the object initialization time and memory consumption. Objects can nest.

Object Literals
Convenient notation for creating new objects. e.g var empty_obj={ };

property name

var emp={ first-name:Suph; last-name:Jabeen; };


property Value

We dont require in case the property names are legal Js names for example
property name

var emp={ first_name:Suphia; last_name:Jabeen; };


property Value

In the first eg is there which isnt a valid for declaring names so is used.

Retrieve
To retrieve value from the objects use emp.[first-name] or

emp.first_name

//incase of a Js legal name

We can also add a property later after the object has been defined For example: emp[first_name]:Suphia emp[last_name]:Jabeen emp.nickname=Suph; //new property added

Js has 3 loops for do while while all are thee same from cpp

The only two values false in Js are false and null rest all are true including the string false.

All the Best

Vous aimerez peut-être aussi