How javascript gets that the variable is a numeric type
The main content of this article is to explain "javascript how to get a variable is a numeric type or a string type", interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how javascript can get whether a variable is a numeric type or a string type.
In javascript, you can use the typeof operator to get whether a variable is a numeric type or a string type, syntax "typeof variable"; if the return value is "number", the variable is a numeric type, and if the return value is "string", the variable is a string type.
The operating environment of this tutorial: windows7 system, javascript1.8.5 version, Dell G3 computer.
Does javascript determine whether the variable is a numerical type? Or a string type?
In javascript, you can use the typeof operator to determine whether a variable is of numeric type or string type.
The typeof operator is used to detect the data type of a given variable or value, and the returned value is the data type name of the Operand, which is a string result.
The format is as follows:
Typeof Operand
Note: the Operand can be a variable or a specific value (that is, literal). The returned values are as follows:
Undefined: indicates that the Operand is undefined
Boolean: indicates that the Operand is a Boolean
String: indicates that the Operand is a string
Number: indicates that the Operand is a number
Object: indicates that the Operand is an object or an array
Function: indicates that the Operand is a function.
Note: a function is also an object, but typeof treats a function as a special case, so when you detect a function, the result is function, not object.
An example of using the typeof operator to detect data types is as follows:
Var miaov = 'ketang'; / / declare the variable and assign a value to the variable console.log (typeof miaov); / / check the variable miaov, and the result is: stringconsole.log (typeof 1); / / detect the number 1, and the result is: numberconsole.log (typeof true); / / detect true, the result is: booleanconsole.log (typeof false); / / detect false, the result is: booleanconsole.log (typeof undefined); / / detect undefined, the result is undefinedconsole.log (typeof null) / / detect null, result: objectconsole.log (typeof {}); / / detect object, result: objectconsole.log (typeof []); / / detect array, result: objectfunction func () {} / / define function console.log (typeof func) / / check the func function type, the result is: 'function' so far, I believe you have a better understanding of "how to get a variable is a numeric type or a string type", you might as well do it in practice! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!