Presentation is loading. Please wait.

Presentation is loading. Please wait.

Mahesh Chandran Pillai.  JavaScript is an implementation of the ECMAScript language standard and is typically used to enable programmatic access to computational.

Similar presentations

Presentation on theme: "Mahesh Chandran Pillai.  JavaScript is an implementation of the ECMAScript language standard and is typically used to enable programmatic access to computational."— Presentation transcript:

1 Mahesh Chandran Pillai

2  JavaScript is an implementation of the ECMAScript language standard and is typically used to enable programmatic access to computational objects within a host environment.  It can be characterized as a prototype-based object-oriented scripting language that is dynamic, weakly typed and has first-class functions Mahesh Chandran Pillai

3  JavaScript 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. Mahesh Chandran Pillai

4  Put dynamic text into an HTML page  React to events  Read and write HTML elements  Validate data  Detect the visitor’s browser  Create cookies Mahesh Chandran Pillai

5  Access other resources such as Files, Databases and Programs  Talk to Web Servers  Give similar output on different browsers  Be encrypted.  Be used with copyrighted data or algorithms Mahesh Chandran Pillai

6  A script that is executed by the browser on a users computer  Instead of the entire page, part of the page is sent to the browser when user requests for the page.  Mostly run in response to an event  For example: Click events, validations.  Direct interaction with client Mahesh Chandran Pillai

7  Requirements › A Text Editor like Notepad, Notepad++, etc…. › Knowledge of basic HTML and form Tags  Ways for Including JavaScript in your HTML page › Direct Insertion  Using ……. inside or tags › Embedded Insertion  Using “Javascript” as prefix in other HTML tags.  › External References  By specifying the “src” attribute in tag.  Mahesh Chandran Pillai

8 JavaScript Skeleton // JavaScript can go here! // But no HTML! // JavaScript can go here too! // But no HTML! Mahesh Chandran Pillai

9  // - single line commenting  /*…..*/ - multiple lines commenting  - Commenting Javascript from old browsers Mahesh Chandran Pillai

10  JavaScript is case-sensitive  ƒ Ending statements with a semicolon is optional.  ƒ Open and Close braces for scoping the embedded Java Script code is mandatory.  ƒ You can apply more than one script in a same HTML file. Mahesh Chandran Pillai

11  Values, Variables, and Literals  Expressions and Operators  Regular Expressions  Statements  Functions  Objects Mahesh Chandran Pillai

12  JavaScript does not have explicit data types  ƒ There is no way of specifying that a particular variable represents an integer, a string or a real.  All JavaScript variables are declared applying the keyword var. › For example: var x, y=7 › Var x=“hello guys” › Y=true  JavaScript recognizes strings, numbers, Boolean values and null Mahesh Chandran Pillai

13 Rules for identifiers  Should start with a letter or an underscore ( _ ).  Case sensitive. Numbers are possible in a name. Scope of variables  Local variables: declared inside a function using var keyword.  Global Variables: declared outside the functions. Mahesh Chandran Pillai

14  Operators: › » >=, ==, +=, ||,, and so on.  Control statements: › If, if….else, for, and so on.  Keywords: › Var, true, false, new, return Mahesh Chandran Pillai

15  if.... else › Syntax: if (condition){code to be executed if condition is true } else {code to be executed if condition is not true }  if.. …else if…. else. if (condition1) { code to be executed } else if (condition2) { code to be executed } else { code to be executed } Mahesh Chandran Pillai

16  Switch …. Case › Syntax: switch(n) { case 1: execute code block 1 break ; case 2: execute code block 2 break ; default: code to be executed if n is different from case 1 and 2 } Mahesh Chandran Pillai

17  For Loop › The for loop is applied when you know in advance, how many times the script should run. › For loop Syntax: var initval; for(initval=startvalue; initval<=endalue; initval=initval+incrval) { code to be executed } Mahesh Chandran Pillai

18  While › Syntax: while (initval<=endvalue) { code to be executed }  Do..While › Syntax: do { code to be executed } while (var<=endvalue) Mahesh Chandran Pillai

19  For … in Loop › The statement is applied to loop (iterate) through the elements of an array or through the properties of an object. › Syntax: for (variable in object) { code to be executed } Mahesh Chandran Pillai

20 Functions can be of two types.  Built in Functions › Functions which are provided by Javascript.  User Defined Functions › A function is identified by the keyword function, followed by a programmer-supplied name for the function, and followed by a set of parentheses that optionally enclose data values needed by the function to carry out its processing. › Syntax: function function_name(parameters) { function-body; } Mahesh Chandran Pillai

21  Calling Functions › You can call a function by using it name followed by parenthesis with parameters if defined. Function_name(parameters); › You can call functions with event handlers › You can avoid functions by writing inline scripts  It is useful only for avoiding small functions. Mahesh Chandran Pillai

22  Alert( message) › Which puts a string into a little announcement box (also called an alert box). › Syntax: alert(“I will show this message!");  Prompt(message, txtmsg) › which asks your visitor for some information and then sets a variable equal to whatever your visitor types. › Syntax: var name = prompt("What's your name?", "put your name here");  Confirm() › Which confirms the users action and returns a Boolean value. › Syntax: confirm(“Do you want to continue”); Mahesh Chandran Pillai

23 Examples:  alert("Hello, world!");  prompt("Pls enter u r name", "enter here ");  confirm("Do you want to continue");

24  document.write (str) › This function will help you to write any string message to the web page. Mahesh Chandran Pillai

25  Date › The Date Object type provides a common set of methods for working with dates and times.  String › The String Object type provides a set of methods for › manipulating strings.  Math › The Math Object type provides a common set of methods for working with mathematical tasks. Mahesh Chandran Pillai

26 NameDescription getDate()The day of the month as an integer from 1 to 31 getDay()The day of the week as an integer where 0 is Sunday and 1 is Monday getHours()The hour as an integer between 0 and 23 getMinutes()The minutes as an integer between 0 and 59 getMonth()The month as an integer between 0 and 11 where 0 is January and 11 is December getSeconds()The seconds as an integer between 0 and 59 getTime()The current time in milliseconds where 0 is January 1, 1970, 00:00:00 getYear()The year, but this format differs from browser to browser Mahesh Chandran Pillai

27  substring(startIndex)  substring(startIndex,endIndex)  charAt(index)  toLowerCase()  toUpperCase()  toString()  valueOf()  Indexof() Mahesh Chandran Pillai

28 NameDescription exp()Value of e raised to the power passed as the argument Abs()Absolute value of the sqrt()Square root of the argument round()Argument rounded up if its decimal value is greater than or equal to 0.5 and rounded down otherwise pow()First argument raised to the power passed as the second argument random()Random number between 0 and 1 min()Lower of the two numbers passed as arguments Max()Higher of the two numbers passed as arguments Log()Natural log of the argument floor()Integer lower than or equal to the number passed as the argument ceil()Integer greater than or equal to the number passed Mahesh Chandran Pillai

29 NameDescription escape(string)Encodes a string from ASCII into an ISO Latin-1. Unescape()encodes a string from ISO Latin-1 to ASCII Eval()Converts a string to integer or float value. It can also evaluate expressions included with a string. isNaN(value)If the value passed is a not a number, the Boolean value of true is returned, if it is a number, it returns false. typeof operatorThis is an operator but its usefulness is similar to a function. This operator returns the type of the object it operates on. parseInt()Converts a string to an integer returning the first integer encountered which is contained in the string. parseFloat()Returns floating point numbers the same as the parseInt function, but looks for floating point qualified strings and returns their value as a float. toString()Converts an object to a string

30  A collection elements in contiguous memory location.  Creating Arrays › Syntax Var arr_name=new Array(elements); › Example var colors = new Array("red", "orange", "yellow", "green", "blue", "indigo", "violet");  Assigning Values var the_answers = new Array(); the_answers[0] = "yes"; the_answers[1] = "no“; Mahesh Chandran Pillai

31  An associative array uses strings instead of numbers to store values.  Examples: var phone_book = new Array(); phone_book[“devu"] = "(415) 555-5555"; phone_book["info"] = "(415) 555-1212";  Length property of array will help you to find the number of elements. Mahesh Chandran Pillai

32  onLoad  onMouseOut and onMouseOver  onReset  onSelect  onSubmit  onUnload  onAbort  onBlur  onChange  onClick  onError  onFocus  OnKeyup  OnKeyDown  OnKeyPress Mahesh Chandran Pillai

33  Event handlers are functions are invoked when an event is raised or fired by the object.  Examples: › board › Click me › change background Mahesh Chandran Pillai


35  The document object lists all the images, links, forms, and other stuff on a web page. Mahesh Chandran Pillai


Download ppt "Mahesh Chandran Pillai.  JavaScript is an implementation of the ECMAScript language standard and is typically used to enable programmatic access to computational."

Similar presentations

Ads by Google