Upgrade to Pro — share decks privately, control downloads, hide ads and more …

javascript part I

Avatar for jamspidy jamspidy
January 27, 2012

javascript part I

javascript powerpoint presentation part1

Avatar for jamspidy

jamspidy

January 27, 2012
Tweet

More Decks by jamspidy

Other Decks in Technology

Transcript

  1. Hi I am Philbert Jay de Silva. Hi I am

    Philbert Jay de Silva. Having a solid fifteen years (15 Yrs) experience in various Having a solid fifteen years (15 Yrs) experience in various phase of System Development Life Cycle, specialized phase of System Development Life Cycle, specialized using COBOL either in mainframe or midrange platform, using COBOL either in mainframe or midrange platform, POWERBUILDER And Visual Basic/VBA/Net for object POWERBUILDER And Visual Basic/VBA/Net for object oriented programming. Working knowledge in Web oriented programming. Working knowledge in Web development using ASP.NET, C#,JAVA,PHP, JAVASCRIPT, development using ASP.NET, C#,JAVA,PHP, JAVASCRIPT, XML, HTML, and SHAREPOINT. XML, HTML, and SHAREPOINT. Hands on IT experience in the following Industries Hands on IT experience in the following Industries Banking, Insurance, Manufacturing, Government, Banking, Insurance, Manufacturing, Government, Retailing Business, and Telecommunication. Retailing Business, and Telecommunication.
  2. Introduction Introduction Name Name Company Affiliation Company Affiliation Title Function

    Title Function Job Responsibility Job Responsibility Programming and database experience Programming and database experience Visual Studio Experience Visual Studio Experience Your expectations for the course Your expectations for the course
  3. Course Objective Course Objective Introduce you to all the key

    concepts of the Introduce you to all the key concepts of the JavaScript language, as well as a full coverage JavaScript language, as well as a full coverage of the JavaScript Syntax of the JavaScript Syntax You will be exposed to examples of building You will be exposed to examples of building web pages that incorporates JavaScript as it web pages that incorporates JavaScript as it’ ’s s primary building blocks. primary building blocks.
  4. JavaScript JavaScript One of the most intriguing and exciting aspects

    of the World One of the most intriguing and exciting aspects of the World Wide Web is its capability to offer interactive content to many Wide Web is its capability to offer interactive content to many people. Thousands upon thousands of pages are linked together people. Thousands upon thousands of pages are linked together across the globe, each accessible with a single mouse click. The across the globe, each accessible with a single mouse click. The Web is the largest collection of information available to a sing Web is the largest collection of information available to a single le person since the beginning of time. As incredible as these person since the beginning of time. As incredible as these notions may be, the users of the Web demand more. As notions may be, the users of the Web demand more. As technology on the Web improves, users want more interaction, technology on the Web improves, users want more interaction, more sophistication, more visually appealing content, and above more sophistication, more visually appealing content, and above all, these users want to be able to create this content all, these users want to be able to create this content themselves. themselves.
  5. JavaScript History JavaScript History Netscape Communications saw the need for

    a bridge Netscape Communications saw the need for a bridge between these Java & HTML technologies. They began between these Java & HTML technologies. They began working on a new scripting language that could have a working on a new scripting language that could have a place between HTML and Java, yet be powerful enough to place between HTML and Java, yet be powerful enough to link the two technologies together. link the two technologies together. When Netscape When Netscape’ ’s new s new scripting language was introduced, it was known as scripting language was introduced, it was known as LiveScript LiveScript. It . It was immediately incorporated into their Navigator product in an was immediately incorporated into their Navigator product in an effort to quickly have it adopted by the Internet community. effort to quickly have it adopted by the Internet community. Soon thereafter, seeing the potential of a joint effort, Soon thereafter, seeing the potential of a joint effort, Netscape Netscape and Sun and Sun teamed to help LiveScript become more mainstream teamed to help LiveScript become more mainstream and to establish it as the standard in the Internet community fo and to establish it as the standard in the Internet community for r Web Web- -based scripting. Because LiveScript syntax was so similar to based scripting. Because LiveScript syntax was so similar to Java Java’ ’s syntax, Sun and Netscape decided to rename their new s syntax, Sun and Netscape decided to rename their new product to make it more recognizable. It would now be called product to make it more recognizable. It would now be called JavaScript. JavaScript.
  6. Learning JavaScript Learning JavaScript JavaScript is based on the powerful

    Java language in its syntax JavaScript is based on the powerful Java language in its syntax and usage, yet is and usage, yet is interpreted, not compiled. interpreted, not compiled. What this means is that the JavaScript application What this means is that the JavaScript application code is downloaded as text into the browser along with the HTML code is downloaded as text into the browser along with the HTML text. The code text. The code is executed within the browser, enabling you to develop simple a is executed within the browser, enabling you to develop simple applications that pplications that can interact with and assist your users. can interact with and assist your users. With JavaScript, you can respond to events from the user such as With JavaScript, you can respond to events from the user such as mouse clicks, mouse clicks, mouse movement over a link, and form input. mouse movement over a link, and form input. You can build dynamic pages that You can build dynamic pages that change according to your user change according to your user’ ’s requests, or even play sounds or run applets s requests, or even play sounds or run applets when a user enters or leaves your page. This type of capability when a user enters or leaves your page. This type of capability at the client level at the client level allows for tremendous interactivity with the users of your Web p allows for tremendous interactivity with the users of your Web pages. ages. The JavaScript language resembles Java, but is simpler and easie The JavaScript language resembles Java, but is simpler and easier to learn. r to learn. A A JavaScript application may be as short as one line or take sever JavaScript application may be as short as one line or take several pages. The al pages. The complexity depends on the extent in which your script interacts complexity depends on the extent in which your script interacts with the page it with the page it is in. One of the first uses of JavaScript for most authors is i is in. One of the first uses of JavaScript for most authors is in form validation. n form validation. Form validation is the ability for an HTML form to check the inp Form validation is the ability for an HTML form to check the input from a user ut from a user before it is submitted, which greatly improves performance on yo before it is submitted, which greatly improves performance on your server as ur server as well as decreases user frustration. Listing 41.1 shows a simple well as decreases user frustration. Listing 41.1 shows a simple example of form example of form validation validation
  7. Authoring with JavaScript Authoring with JavaScript Creating a JavaScript program

    is a relatively simple process. Us Creating a JavaScript program is a relatively simple process. Using any text ing any text editor, you may begin typing in JavaScript statements to expand editor, you may begin typing in JavaScript statements to expand the role of your the role of your current HTML pages current HTML pages, create entirely new pages using only JavaScript, or mix both , create entirely new pages using only JavaScript, or mix both HTML and JavaScript. This section will cover some of the issues HTML and JavaScript. This section will cover some of the issues and syntax in and syntax in creating a JavaScript application, as well as information on how creating a JavaScript application, as well as information on how to embed your to embed your JavaScript code into your HTML documents. JavaScript code into your HTML documents. Creating Your Script Creating Your Script In order for your browser to recognize that there is JavaS In order for your browser to recognize that there is JavaScript code in cript code in your file, two special tags have been introduced. your file, two special tags have been introduced. <SCRIPT>...</SCRIPT> <SCRIPT>...</SCRIPT> Between these two tags, JavaScript code may be inserted and Between these two tags, JavaScript code may be inserted and the browser will the browser will recognize the JavaScript code while loading your page. The <SCRI recognize the JavaScript code while loading your page. The <SCRIPT> tag also PT> tag also has attributes that can be specified. has attributes that can be specified. <SCRIPT LANGUAGE= <SCRIPT LANGUAGE=” ”JavaScript JavaScript” ”>...</SCRIPT> >...</SCRIPT>
  8. In order to create a script, simply use your favorite

    text or In order to create a script, simply use your favorite text or HTML editor HTML editor and begin typing in javascript. and begin typing in javascript. <HTML> <HTML> <HEAD> <HEAD> <SCRIPT> <SCRIPT> document.write( document.write(“ “<H1>JavaScript is Fun!</H1> <H1>JavaScript is Fun!</H1>” ”) ) </SCRIPT> </SCRIPT> </HEAD> </HEAD> <BODY> <BODY> <h2>This is normal HTML.</h2> <h2>This is normal HTML.</h2> </BODY> </BODY> </HTML> </HTML>
  9. Running Your Script Running Your Script Running your JavaScript code

    is as easy as viewing an HTML page. Running your JavaScript code is as easy as viewing an HTML page. Once Once your code is complete, simply load the page into your browser fo your code is complete, simply load the page into your browser for instant r instant results. results. This ability to instantly run and check your JavaScript code is This ability to instantly run and check your JavaScript code is another powerful feature of JavaScript. In the development and t another powerful feature of JavaScript. In the development and testing esting process of a JavaScript application, your computer does not need process of a JavaScript application, your computer does not need to be to be connected to a network. You can edit, test, and execute your Jav connected to a network. You can edit, test, and execute your JavaScript aScript applications without ever being online. This can be a real advan applications without ever being online. This can be a real advantage when tage when hourly connect charges are a concern. Also, because you are test hourly connect charges are a concern. Also, because you are testing your ing your applications locally, load times will be extremely fast, and bec applications locally, load times will be extremely fast, and because ause JavaScript executes the code immediately, your entire developmen JavaScript executes the code immediately, your entire development process t process will be extremely efficient and rewarding. will be extremely efficient and rewarding.
  10. JavaScript Fundamentals JavaScript Fundamentals JavaScript components include variables and values,

    data types, JavaScript components include variables and values, data types, literals, literals, properties, arrays, and comment statements. As the basic buildin properties, arrays, and comment statements. As the basic building blocks of g blocks of JavaScript, an understanding of these fundamentals is the first JavaScript, an understanding of these fundamentals is the first step toward the step toward the mastery of the JavaScript language. mastery of the JavaScript language. JavaScript variables are similar to variables in any other programming language; they hold values that you use in your application. JavaScript enables you to name your case-sensitive variables so you may reference them elsewhere in your code. You can name variables anything you wish. You may opt to use descriptive names such as number_of_times_clicked, or short, generic names such as foo. The only restrictions on variable names is that they must begin with a letter or underscore (_). JavaScript variables can contain the following different types of values: numbers, for example, 14 or 1.25 logicals (Boolean), can be True or False strings, for example, Hello World JavaScript also recognizes the null keyword for specifying null values for variables. JavaScript has reduced the confusion in deciding which data type to use for different types of numbers. JavaScript uses a single data type for numbers, which means that a JavaScript number can contain the equivalent of integers, reals, and doubles without the need for specialized types. In addition, JavaScript handles Date objects with this same data type, further simplifying code development under JavaScript.
  11. JavaScript components include variables and values, data types, JavaScript components

    include variables and values, data types, literals, literals, properties, arrays, and comment statements. As the basic buildin properties, arrays, and comment statements. As the basic building blocks of g blocks of JavaScript, an understanding of these fundamentals is the first JavaScript, an understanding of these fundamentals is the first step toward the step toward the mastery of the JavaScript language. mastery of the JavaScript language. JavaScript variables are similar to variables in any other programming language; they hold values that you use in your application. JavaScript enables you to name your case-sensitive variables so you may reference them elsewhere in your code. You can name variables anything you wish. You may opt to use descriptive names such as number_of_times_clicked, or short, generic names such as foo. The only restrictions on variable names is that they must begin with a letter or underscore (_). JavaScript variables can contain the following different types of values: numbers, for example, 14 or 1.25 logicals (Boolean), can be True or False strings, for example, Hello World JavaScript also recognizes the null keyword for specifying null values for variables. JavaScript has reduced the confusion in deciding which data type to use for different types of numbers. JavaScript uses a single data type for numbers, which means that a JavaScript number can contain the equivalent of integers, reals, and doubles without the need for specialized types. In addition, JavaScript handles Date objects with this same data type, further simplifying code development under JavaScript.
  12. The var statement is used to declare variables in JavaScript.

    Each variable is given a name and optionally an initial value. Outside of a function, the var statement is optional, but it is highly recommended that you always use var to avoid the possibility of overwriting local variables with global variables. • Local variables are generally declared within a function with the intention that only the function will be able to use the variable. • Global variables are declared outside of any function, making the variable available to any function. Therefore, to avoid conflict, the var statement will ensure your variables safety in these situations. syntax of var statement: var varname [= value] [..., varname [= value] ] Multiple variables may be declared from one var statement. The following example demonstrates this: var num_cans = 10, price_per_can = 2.0;
  13. Data Types JavaScript fully supports variables of different data types,

    but does so loosely to enable you, the programmer, to more quickly develop applications without the headache of strict type specification prior to execution. JavaScript applications can handle a great number of different types of data, but JavaScript manages to do this with only three distinct data types. In addition, JavaScript can decide for you what data type your variable should be during script execution. Converting between different types is very easy and straightforward. Data types are converted automatically when your JavaScript application runs. JavaScript follows one simple rule when converting types; it performs the conversion from left to right. In other words, the right-hand operand will be converted to the type of the left-hand operand. No matter how complex the conversion, JavaScript always follows this left-to-right approach. For example, if you had the following variables: var1 = “10” var2 = 20 Then performed the following statements: x = var1 + var2 y = var2 + var1 The first statement would convert var2 to a string, because the operand on the left, var1, is a string. The result would be that x would contain the string “1020”. In contrast, the second statement would convert var1 to a number, because the operand to its left, var2, is a number. The two numbers would then be added together to form the result of 30 in y.
  14. Literals Many times when creating new variables, you need to

    specify an initial value. These types of fixed values are called literals. Literals are not variables, but rather, constant expressions of values for data types. For example, some literal values could include. 24 72.745 “programming is fun” When expressing literal values for integers, you may use three different bases. You may use decimal (base 10), hexadecimal (base 16), or octal (base 8) format. To specify a decimal literal, simply use a series of digits without any leading zeros. For example 42 (a decimal literal) To specify an octal literal, precede the number with a leading 0 (zero). Octal literals can only include digits 0-7. For example 010 (an octal literal) Finally, when specifying a hexadecimal literal, precede the number with a leading 0x (or 0X). Hexadecimal literals can include all digits (0 - 9) and the letters a-f and A-F. For example: 0xFF (a hexadecimal literal)
  15. A floating-point literal is specified by the following parts: a

    decimal integer, a decimal point, another decimal integer, an exponent, and a type suffix. The exponent is specified by using an e or E followed by an integer that can be signed by proceeding it with a - or a +. A floating-point literal should have at least one digit plus either a decimal point or e or E. example 4.25 (floating point literals) .4e3 2E-8 -6.2e9 A Boolean literal is specified by one of two values: true or false. string literals are specified by using zero or more charac string literals are specified by using zero or more characters enclosed in ters enclosed in double or single quotes. double or single quotes. example example “ “banana banana” ” (string literals) (string literals) ‘ ‘pear pear’ ’ “ “goodbye goodbye \ \t forever t forever” ”
  16. JavaScript special characters for string literals: b (backspace) b (backspace)

    \ \f (form feed) f (form feed) \ \n (new line character) n (new line character) \ \r (carriage return) r (carriage return) \ \t (tab character) t (tab character)
  17. Object properties Object properties can be either variables or functions.

    These properties can can be either variables or functions. These properties can be accessed in two be accessed in two different ways. The first approach to accessing the properties o different ways. The first approach to accessing the properties of objects is as f objects is as follows: objectName.propertyName Once you have an object, creat follows: objectName.propertyName Once you have an object, creating properties ing properties for that object is as simple as assigning a value to a property for that object is as simple as assigning a value to a property name. For example, name. For example, suppose you had an object named person. To give the person objec suppose you had an object named person. To give the person object some t some properties, you would simply use the following statements: properties, you would simply use the following statements: person.name = person.name = “ “John John” ”; ; person.age = 24; person.age = 24; person.height = 68; person.height = 68; person.weight = 155; person.weight = 155; These statements would add the four properties name, age, These statements would add the four properties name, age, height, and weight to height, and weight to the person object. the person object.
  18. Reserved Words Reserved Words JavaScript currently contains 53 reserved words.

    These JavaScript currently contains 53 reserved words. These words words cannot be used for variable, function, method, or object names. cannot be used for variable, function, method, or object names. Some of the words are not currently being used by JavaScript, bu Some of the words are not currently being used by JavaScript, but t rather are reserved for future use. rather are reserved for future use. abstract abstract extends extends int int super super boolean boolean false false interface interface switch switch break break final final long long synchronized synchronized byte byte finally finally native native this this case case float float new new throw throw catch catch for for null null throws throws char char function function package package transient transient class class goto goto private private true true const const if if protected protected try try continue continue implements implements public public var var default default import import return return void void do do in in short short while while double double instanceof instanceof static static with with else else
  19. Operators In JavaScript, as in other languages, operators are used

    to perform actions between two operands. For example, when assigning values to variables, you would use assignment operators; when adding numbers together, you would use arithmetic operators; and when concatenating two strings together, you would use string operators. String Operators String Operators The JavaScript string operators include the comparison opera The JavaScript string operators include the comparison operators mentioned tors mentioned previously as well as the concatenation operator (+) for concate previously as well as the concatenation operator (+) for concatenating two nating two strings together. For example, the following statement strings together. For example, the following statement “ “Java Java” ” + + “ “Script Script” ” would result in the string would result in the string “ “JavaScript JavaScript” ” You may also use the shorthand notation for string concaten You may also use the shorthand notation for string concatenation. For example, ation. For example, if a string str1 contains the value if a string str1 contains the value “ “Java Java” ”, the following statement , the following statement str1 += str1 += “ “Script Script” ” would also result in the string would also result in the string “ “JavaScript JavaScript” ”. .
  20. Comparison Operators Comparison Operators When performing looping or conditional statements

    in JavaScript, When performing looping or conditional statements in JavaScript, you may you may need to use a comparison of two values to continue or to termina need to use a comparison of two values to continue or to terminate your loop te your loop or condition. In JavaScript, when performing a comparison, you m or condition. In JavaScript, when performing a comparison, you must use a ust use a comparison operator between the two values you are comparing. Wh comparison operator between the two values you are comparing. What you get at you get in return is a Boolean value representing the outcome of the com in return is a Boolean value representing the outcome of the comparison. parison. Operator Operator Result Result Equal (==) Equal (==) Returns true if the operands are equal Returns true if the operands are equal Not equal (!=) Not equal (!=) Returns true if the operands are not equal Returns true if the operands are not equal Greater than (>) Greater than (>) Returns true if the left operand is greater than the Returns true if the left operand is greater than the right operand right operand Less than (<) Less than (<) Returns true if the right operand is greater then the Returns true if the right operand is greater then the left operand left operand Less than or equal Less than or equal to (<=) to (<=) Returns true if the left operand is less than or equal Returns true if the left operand is less than or equal to the right operand to the right operand Greater than or Greater than or equal to (>=) equal to (>=) Returns true if the left operand is greater than or Returns true if the left operand is greater than or equal to the right operand equal to the right operand
  21. Arithmetic Operators Arithmetic Operators JavaScript supports eight basic arithmetic operators.

    JavaScript supports eight basic arithmetic operators. Operator Operator Function Function Performed Performed Example Example + + Addition Addition x = a + b x = a + b - - Subtraction Subtraction y = a y = a - - b b * * Multiplication Multiplication x = a * b x = a * b / / Division Division y = a / b y = a / b % % Modulus Modulus 12 % 5 = 2 12 % 5 = 2 ++ ++ Increment Increment x++ x++ -- -- Decrement Decrement y y-- -- - - Unary negation Unary negation x = x = - -y y
  22. Logical Operator Logical Operator Logical operators enable you to test

    two values and ret Logical operators enable you to test two values and return a values urn a values based on the two tested. based on the two tested. Operator Operator Function Performed Function Performed Example Example && && AND, true if both are true AND, true if both are true expr1 && expr2 expr1 && expr2 || || OR, true if either is true OR, true if either is true expr1 || expr2 expr1 || expr2 ! ! NOT, negates operand NOT, negates operand !expr !expr
  23. Conditional Statements and looping JavaScript looping and conditional statements allow

    for a great variety of tasks to be performed in your application. Using any of JavaScript’s looping statements, you can repeat a series of statements until a certain condition is met. Additionally, with conditional statements, you can limit the execution of JavaScript code based on a certain criteria, or update information based on yet another criteria.
  24. if...else The if...else is JavaScript’s conditional testing statement. This statement

    enables you to test a condition and if it is true, execute a block of code. Optionally you can execute a block of code if the statement evaluates to false. This is done using the else statement. The if...else statement may be nested. Following is the syntax for the if...else statement: if (condition) { statements } [else { else statements }] An example of this statement follows: if ( rate_book(javascript_book) == “*****”) { good = true; } else good = false; Again, as in other JavaScript statements, if a single statement follows the if or else statement, the use of the brace pairs ({ }) is optional.
  25. Conditional Expression A conditional expression in JavaScript is a way

    to test a value whose result can be one of two values. For example old_enough = (age >= 16) ? “Drive Home” : “Walk Home” This statement first tests the condition within the parenthesis. If age is indeed greater than or equal to 16, then the first value after the question mark (?) is chosen. Otherwise, if the comparison is false, the second value after the question mark is chosen. If age were set to 17, old_enough would be set to Drive Home. with The JavaScript with statement enables you to specify an object as the default object when executing statements within its block of code. The syntax for the with statement is as follows: with (object) { statements } An example of the with statement that uses the Math object as the default object follows: with (Math) { a = PI * r*r; x = r * cos(theta); y = r * sin(theta);
  26. switch A switch statement allows a program to evaluate an

    expression and attempt to match the expression's value to a case label. If a match is found, the program executes the associated statement. The program first looks for a label matching the value of expression and then executes the associated statement. If no matching label is found, the program looks for the optional default statement, and if found, executes the associated statement. If no default statement is found, the program continues execution at the statement following the end of switch. The optional break statement associated with each case label ensures that the program breaks out of switch once the matched statement is executed and continues execution at the statement following switch. If break is omitted, the program continues execution at the next statement in the switch statement.
  27. Syntax switch (expression){ case label : statement; break; case label

    : statement; break; ... default : statement; } Arguments expression is the value matched against label. label is an identifier used to match against expression. statement is any statement.
  28. Example In the following example, if expression evaluates to "Bananas",

    the program matches the value with case "Bananas" and executes the associated statement. When break is encountered, the program breaks out of switch and executes the statement following switch. If break were omitted, the statement for case "Cherries" would also be executed. switch (i) { case "Oranges" : document.write("Oranges are $0.59 a ound.<BR>"); break; case "Apples" : document.write("Apples are $0.32 a pound.<BR>"); break; case "Bananas" : document.write("Bananas are $0.48 a pound.<BR>"); break; case "Cherries" : document.write("Cherries are $3.00 a pound.<BR>"); break; default : document.write("Sorry, we are out of " + i + ".<BR>"); } document.write("Is there anything else you'd like?<BR>");
  29. Looping for The for statement enables you to create a

    loop in JavaScript that can initialize a statement, update an expression, and loop until a condition is met. This statement consists of three optional expressions. These expressions are all enclosed in a single set of parenthesis and are separated by a semicolon (;). Following the for loop statement is a block of code to be executed in the loop. The syntax for a for loop follows: for ([initial statement]; [condition]; [update expression]) { statements } for (var i = 0; i < 10; i++) { total = total + i; display_total(total); } }
  30. while The while statement in JavaScript is very similar to

    the for statement, but is more simple to use. The while statement will keep executing a block of code it contains until the condition it is testing is false. Following is the syntax for the while statement: while (condition) { statements } Following is an example of the while statement in use: money = 0.00; while (money < 100.00) { money += 5.00; } This example continues to loop until the variable money reaches its goal of 100.00. Note that the second zero after the decimal point is not needed, but is used to make code reading easier and to signify to the code reader that we are using currency. The extra zero has no effect on the final outcome of the program.
  31. break and continue In a while or for loop, a

    break statement terminates the loop and continues executing the code following the terminated loop. syntax of a break statement is the statement itself with no other options: Break Here’s an example of a break statement that terminates when a variable reaches a certain limit: function func(x) { var i = 0; while (i < 5) { if (i == 2) break; i++; } return i*x; } In this example, when the variable i reaches the value of 2, the while loop terminates.
  32. The continue statement terminates the execution of the current block

    in a loop and continues the loop with the next iteration. The syntax of a continue statement is the statement itself with no other options: continue Here’s an example of a continue statement that terminates when a variable reaches a certain limit: function func(x) { var i = 0; while (i < 5) { if (i == 2) continue; i++; } return i*x; }
  33. Arrays Because JavaScript uses the same data structure for the

    storage of properties and arrays, they generally are treated as the same thing. In other words, they are so closely related that you may access properties through arrays and vice versa. For example, you could access the properties mentioned in the prior section as follows: person[“name”] = “John”; person[“age”] = 24; person[“height”] = 68; person[“weight”] = 155; In addition, you may also use array indices to access your properties; for example, to access the “name” property in the person object, since it is the first property, you can use the following: person[0] = “John” As you can see, JavaScript is very lenient in the use and access of object properties. This simplicity in the JavaScript allows you to spend more time on the development of applications, rather than specifics of the language. function MakeArray(n) { this.length = n; for (var i = 1; i <= n; i++) { this[i] = 0 } return this } }
  34. To use this function, simply use the JavaScript new command,

    for example myarray = new MakeArray(10); This creates an array called myarray with 10 elements, with all elements initially set to zero.
  35. Creating Arrays With Literal Notation In addition to creating an

    array using its constructor function, you can create it using literal notation. Syntax arrayName = [element0, element1, ..., elementn] Properties arrayName is the name of the new array. element is a list of values for the array's elements. When this form is specified, the array is initialized with the specified values as its elements, and the array's length is set to the number of arguments. Description You do not have to specify all elements in the new array. If you put 2 commas in a row, the array will be created with spaces for the unspecifed elements, as shown in the second example. If an array is created using literal notation in a top-level script, JavaScript interprets the object each time it evaluates the expression containing the array literal. In addition, a literal used in a function is created each time the function is called. Example The following example creates the coffees array with three elements and a length of three: coffees = ["French Roast", "Columbian", "Kona"] The following example creates the fish array, with 2 prespecified elements and one empty element: fish = ["Lion", , "Surgeon"] With this expression fish[0] is "Lion", fish[2] is "Surgeon", and fish[1] is undefined.
  36. Exercises Exercises Create a JavaScript Application. Create a JavaScript Application.

    Which prints your name, age and birthdate by using appropriate v Which prints your name, age and birthdate by using appropriate variables to ariables to store these data. Use these variables to display the values in a store these data. Use these variables to display the values in a web page. web page. Which prints the multiplication table of any number display the Which prints the multiplication table of any number display the values in a values in a web page web page Which prints two numbers, one incrementing by one from zero and Which prints two numbers, one incrementing by one from zero and the the other decrementing by one from 10 values other decrementing by one from 10 values Which prints the numbers 1 to 100. For all numbers with multiple Which prints the numbers 1 to 100. For all numbers with multiples of 5, s of 5, print the word FIZZ, for multiples of 7 the word BUZZ, and for m print the word FIZZ, for multiples of 7 the word BUZZ, and for multiples of ultiples of both FIZZ BUZZ both FIZZ BUZZ Which prints the first ten numbers of the Fibonacci series Which prints the first ten numbers of the Fibonacci series (0 1 1 2 3 5 8 13 (0 1 1 2 3 5 8 13… ….) .)