You are on page 1of 11

Unit-3 Javascript Basics It is a scripting language.

It was designed to add interactivity to html pages & light weight programming languages. Dynamic text into an html page. Javascript can be used to validate form data before it is submitted to a server. It is used to create cookies i.e used to store & retrieve information on the visitors computer. Client side javascript-enables the enhancement & manipulation of web pages & client browsers Server side javascript-enables back-end access to databases,file system & servers.

Operators
1 Arithmetic operator-are used to perform arithmetic between variables & values. + , - , * , / , % , ++ , -2 Assignment operator-they are used to assign values. Operator Example Same As x=x+y x=x-y x=x*y x=x/y x=x%y

= += -= *= /= %=

x=y x+=y x-=y x*=y x/=y x%=y

3 Comparison Operator-are used in logical statements to determine equality or difference between the variables.
Operator Description

== === != > < >= <=

Is equal to Is exactly equal to Is not equal Is greater than Is less than Greater than or equal to Less than or equal to

4 % Modulus returns only the remainder <html> <script language=javascript> a=7%2; document.write(a=,a); </script> </html>

5 Increment 6 Decrement 7 Unary operator 8 Logical operator


Operator && || ! Description and or not Example X<10 && y>1 X==5 || y==5 !(x==y)

Statements 1 for loop 2 break 3 continue 4 for in 5 comment: single line comment, multi-line comment. 6 If statement 7 if-else statement 8 if-else if else 9 switch statement

Array-It is used to store multiple values in a single variable. Object properties: 1 length-returns the number of elements in an array. Method: Concat()-joins two or more arrays,& returns a copy of the joined array Join()-joins all elements of an array into a string Reverse()-reverses the order of the elements In an array Sort()-sorts the elements of an array.

Date-it is used to work with dates & times.date object is created with new Date() Four ways to instantiate date object Var d=new Date(); Var d=new Date(milliseconds); Var d=new date(datestring); Var d=new date(year,month,day,); Method getDate()-returns the day of the month(1-31) getDay()-returns the day of the week(0-6) getHours()-returns the hour(0-23) getMinutes()-returns the minutes(0-59) getMonth()-returns the month(0-11) getSeconds-returns the seconds(0-59) getTime-returns the no of milliseconds since midnight jan 1,1970

Math object methods abs(x)-returns the absolute value of x pow(x,y)-returns the value of x to the power of y random()-returns a random number between 0 & 1 round(x)-round x to the nearest integer. Number objects Maxvalue-returns the largest number possible in javascript Min value-returns the smallest number possible in javascript.

String String object-is used to manipulate a stored piece of text.they are created with new string() Property Length-returns the length of a string charAt()-returns the character at the specified index Concat()-joins two or more strings,& returns a copy of the joined strings Replace()-searches for a match between a substring & a string,& replaces the matched substring with a new substring. Search()-searches for a match between a regular exp & a string & returns the position of the match

Split()-splits a string into an array of substring. Substr()-extracts the characters from a string, Tolowercase()-converts a string to lowercase letters Touppercase()-converts a string to uppercase letters

You might also like