Danh mục

Beginning Ajax with ASP.NET- P5

Số trang: 15      Loại file: pdf      Dung lượng: 357.48 KB      Lượt xem: 8      Lượt tải: 0    
Hoai.2512

Phí tải xuống: miễn phí Tải xuống file đầy đủ (15 trang) 0
Xem trước 2 trang đầu tiên của tài liệu này:

Thông tin tài liệu:

Beginning Ajax with ASP.NET- P5:Thank you for purchasing Beginning Ajax with ASP.NET. We know that you have a lot of options whenselecting a programming book and are glad that you have chosen ours. We’re sure you will be pleasedwith the relevant content and high quality you have come to expect from the Wrox Press line of books.
Nội dung trích xuất từ tài liệu:
Beginning Ajax with ASP.NET- P5Chapter 3 /* These are some more comments. This is useful for a larger set of comments that is written in a paragraph like fashion. */Datatypes There are three basic, or primitive, datatypes in JavaScript: string, number, and boolean types. A boolean type can contain either a true or false value. Number types can contain either an integer or floating- point number. var boolVar = true; var numberVar = 8.13; var stringVar = “This is a string”; The number datatype can have special values. These special values are Infinity and NaN. ❑ A number variable is given the value of Infinity when its maximum capacity is exceeded. Similarly, a number variable is given the value of –Infinity when its minimum value is exceeded. ❑ A number variable can also have a value of NaN, which stands for Not a Number, when the vari- able is assigned the value of an undefined operation, such as dividing zero by zero. Infinity values can be compared, and all values that equate to infinity are equal — that is, any result of an operation that equals infinity is equal to any other operation that results in a value of infinity. Any oper- ation involving a value of infinity causes the entire result to be equal to infinity. Unlike infinity, NaN must be explicitly tested for, using the isNaN() function.Escape Codes Strings can contain special characters such as backspaces, tabs, and carriage returns by “escaping” the characters, that is, by using an escape code to represent the character. Escape codes in strings are pre- fixed by a backslash. The list of escape codes is given in the following table. Escape Code Character or Value Represented \b Backspace \r Carriage return \n Linefeed or newline \t Horizontal tab \v Vertical tab \f Form feed \” Double quotation mark \’ Single quotation mark36 JavaScript and the Document Object Model Escape Code Character or Value Represented \\ Backslash \000 Latin-1 character represented by a three-digit octal value in the range 000–377, for example, \056. \xHH Latin-1 character represented by a two-digit hexadecimal number in the range of 00–FF, for example, \xA0. The following is an example of using escape codes: var s = “This is a tab\tThis is a newline\nI am on a new line”;Weak or Dynamic Typing JavaScript supports the notion of weak typing, or dynamic typing. This means that the type of a variable is inferred from the data it contains. This is why there is only one way to declare variables — by using the var keyword. Try this test: var v = “Some String Data”; alert(typeof v); v = 5; alert(typeof v); In the first instance, a message box will be displayed showing that the type of v is a string. In the second instance, the type of v is a number. The type of the v variable has been inferred, and in fact changed, according to what type of data it contains. The typeof statement is an operator that returns the type of the variable being examined. This operator will return a value of object, boolean, number, string, function, and undefined depending on the argument specified.Composite Types JavaScript also has support for more complex datatypes known as composite types. Composite types can contain not only primitive types, such as a string or number, but also other composite types. The three composite types are arrays, objects, and functions. However, both the array and the function are really just special kinds of objects. An easy way to think of a composite type is an object that can contain any other type of object or objects. An array is the typical composite type and will contain a list of other objects (which may be integers, strings, or custom objects) as a sequential list of elements. An array will typically contain a list of objects of the same type (all integers for example), but it is not limited to just that. Mixing datatypes within arrays can generally lead to confusing code, which may result in hard-to-track bugs. This practice is generally not recommended. 37Chapter 3 Composite types are required where there is a need for an object to contain or handle a logically grouped set of data. For example, an array might be used to store a list of countries or states. Arrays are an ordered set of values and can be defined in a number of ways. var array1 = [1,”string data”,4,5,”6”]; // Mixing data types var array2 = new Array(4); array2[0] = “zero”; array2[1] = “one”; array2[2] = “two”; array2[3] = “three”; var array3 = new Array(1,”two”,3,4); // Mixing data types You can access the values in an array by using an index value representing the element number con- tained at the position in the array: var val1 = array1[0]; var val2 = array1[1]; Objects can contain any type of data and are the primary mechanism for data storage and browser inter- action. Objects can contain data, which are referred to as properties, and functions, which are referred to as methods. Methods ...

Tài liệu được xem nhiều: