Home > Web Front-end > JS Tutorial > body text

Operation rules of Js typeof

巴扎黑
Release: 2016-12-06 09:46:49
Original
1344 people have browsed it

typeof is a unary operation, placed before an operand, and the operand can be of any type. Its return value is a string describing the type of the operand.
I need to clarify:
The typeof operator returns type information as a string. There are six possible return values ​​of typeof: "number," "string," "boolean," "object," "function," and "undefined.". Parentheses in typeof syntax are optional.
typeof is a unary operator, the result it returns is always a string, and it returns different results for different operands.
The specific rules of Typeof operation are as follows:
1. For operands of numeric type, the value returned by typeof is number. For example: typeof(1), the returned value is number.
The above are regular numbers. For unconventional number types, the result returned is also number. For example, typeof(NaN), NaN represents a special non-numeric value in JavaScript, although it itself is a numeric type.
In JavaScript, there are several special number types:
Infinity represents infinity, the special value NaN, the special non-numeric value Number.MAX_VALUE, the largest number that can be represented, Number.MIN_VALUE, the smallest number that can be represented (closest to zero) Number. NaN is a special non-numeric value. Number.POSITIVE_INFINITY represents the special value of positive infinity. Number.NEGATIVE_INFINITY represents the special value of negative infinity.
For the above special types, when using typeof for operation, the result will be number.
2. For string types, the value returned by typeof is string. For example, the value returned by typeof("123") is string.
3. For Boolean types, the value returned by typeof is boolean. For example, the value returned by typeof(true) is boolean.
4. For objects, arrays, and null, the returned value is object. For example, the values ​​returned by typeof(window), typeof(document), and typeof(null) are all objects.
5. For function types, the returned value is function. For example: the values ​​returned by typeof(eval) and typeof(Date) are functions.
6. If the operand is not defined (such as a non-existent variable, function or undefined), undefined will be returned. For example: typeof(sss), typeof(undefined) both return undefined.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template