![]() ![]() Method definition is covered in Chapter 9. sort ( ) // The object-oriented version of sort(a). Instead, we invoke the sort() method of a:Ī. To sort the elements of an array a, for example, we don’t pass a to a sort() function. Loosely, this means that rather than having globally defined functions to operate on values of various types, the types themselves define methods for working with values. JavaScript supports an object-oriented programming style. (JavaScript programmers do sometimes need to take care to ensure that values do not inadvertently remain reachable-and therefore nonreclaimable-longer than necessary.) When a value is no longer reachable-when a program no longer has any way to refer to it-the interpreter knows it can never be used again and automatically reclaims the memory it was occupying. This means that a JavaScript programmer generally does not need to worry about destruction or deallocation of objects or other values. The JavaScript interpreter performs automatic garbage collection for memory management. They are covered in detail in Chapters 8 and 9. Like any JavaScript value that is not a primitive value, functions and classes are a specialized kind of object. JavaScript differs from more static languages in that functions and classes are not just part of the language syntax: they are themselves values that can be manipulated by JavaScript programs. All of these types are covered in Chapter 11. ![]() Error and its subtypes represent errors that can arise when executing JavaScript code. The Date type represents dates and times and supports rudimentary date arithmetic. ![]() The RegExp type represents textual patterns and enables sophisticated matching, searching, and replacing operations on strings. Various “typed array” types facilitate operations on arrays of bytes and other binary data. A Map object represents a mapping from keys to values. In addition to basic objects and arrays, JavaScript defines a number of other useful object types. The JavaScript language includes special syntax for working with arrays, and arrays have some special behavior that distinguishes them from ordinary objects. The language also defines a special kind of object, known as an array, that represents an ordered collection of numbered values. One very special object, the global object, is covered in §3.7, but more general and more detailed coverage of objects is in Chapter 6.Īn ordinary JavaScript object is an unordered collection of named values. An object (that is, a member of the type object) is a collection of properties where each property has a name and a value (either a primitive value or another object). Symbols are covered briefly in §3.6.Īny JavaScript value that is not a number, a string, a boolean, a symbol, null, or undefined is an object. ES6 adds a new special-purpose type, known as Symbol, that enables the definition of language extensions without harming backward compatibility. Each value is typically considered to be the sole member of its own special type. The special JavaScript values null and undefined are primitive values, but they are not numbers, strings, or booleans. A significant portion of this chapter is dedicated to a detailed explanation of the numeric (§3.2) and string (§3.3) types in JavaScript. JavaScript’s primitive types include numbers, strings of text (known as strings), and Boolean truth values (known as booleans). JavaScript types can be divided into two categories: primitive types and object types. It begins with an overview and some definitions. This chapter explains types, values, and variables in JavaScript. The way that variables work is another fundamental characteristic of any programming language. Variables have names, and they allow use of those names in our programs to refer to values. ![]() When a program needs to retain a value for future use, it assigns the value to (or “stores” the value in) a variable. Computer programs work by manipulating values, such as the number 3.14 or the text “Hello World.” The kinds of values that can be represented and manipulated in a programming language are known as types, and one of the most fundamental characteristics of a programming language is the set of types it supports. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |