官术网_书友最值得收藏!

Fixed Types

Fixed types are types that have no variation of value. Unlike numbers, which may have any combination of digits, an optional minus sign (for negative numbers), a decimal point, or a scientific notation, a fixed type is always one simple value or value group.

In JavaScript, the available fixed types include null, undefined, and Booleans (true and false). These values are static and cannot change. If a variable contains one of these values, it is then strictly equal to the value itself. Fixed types are more of a representation of a situation than actual data. For instance, true is a fixed representation of truthfulness and false is a fixed representation of falsehood. The values are not quantifiable in the real world but are representative of logic that software directly deals with.

The null Value

null, in mathematical terms, denotes a value that is not present. In JavaScript, null is a static value that's used to mean no value. In other languages, this would be equivalent to nil or void.

null is a useful value for dereferencing variables or for returning a value from a function when no value can be returned. For instance, a function may return an object from an array if the item is present but may return null if it is not.

The undefined Value

undefined is similar to null in many ways and, due to this, the two values are often misused. undefined is the value contained in any variable that is declared first, but not assigned a value. It is also the value that's been returned from a function that does not explicitly return a value using the return keyword and it is the value that's returned from a statement (an action with no resulting value).

When working with undefined, you should always anticipate it, but never assign it to a variable or return it explicitly from a function. In such circumstances, you should use null.

Boolean Values

Boolean is a term named after George Boole, a nineteenth-century English mathematician and philosopher. It is used to denote the values true and false. These values may be assigned to variables and are strictly equivalent to their value, like null.

Booleans are unique among the types supported by JavaScript because they are indirectly comparable to other types and expressions. The logical operators described in Chapter 3, Programming Fundamentals, of this book, for instance, all result in a Boolean value.

主站蜘蛛池模板: 常州市| 兰州市| 丰县| 陇南市| 乌什县| 麟游县| 海南省| 蒲城县| 井研县| 周至县| 合作市| 衡阳县| 商水县| 太和县| 神池县| 汶川县| 横峰县| 睢宁县| 海南省| 汝南县| 海淀区| 潜江市| 梓潼县| 中牟县| 彭阳县| 高唐县| 嘉义县| 阜阳市| 遵义市| 卢湾区| 黑河市| 类乌齐县| 鄂尔多斯市| 西贡区| 澎湖县| 四子王旗| 江口县| 乐都县| 额敏县| 沈阳市| 宣武区|