Home >Web Front-end >JS Tutorial >Detailed explanation of JS data type examples

Detailed explanation of JS data type examples

小云云
小云云Original
2018-03-20 17:34:171054browse

We have shared a lot with you about the data types of JS. This article mainly continues to share with you detailed examples of JS data types, hoping to help everyone.

The 6 data types returned by typeof():

number, string, boolean, undefined, object, function

Display type Six ways of conversion:

Number(mix), parserInt(string,radix), parseFloat(string), toString(), String(mix), Boolean()

1. Number(mix) Non-numeric elements use this method to return NaN (including half numbers and half string parameters)

2. parserInt(string,radix) returns the first non-numeric character Number, the second parameter is the conversion base (2-36 hexadecimal), set this parameter to convert the target variable of the conversion base into a decimal number

3, parseFloat(string) returns except the first The first non-digit number before a decimal point

4. toString() variable.toString(), convert the variable into a string. This method cannot be called for null and undefined

5. String(mix) All parameters put in can be converted into strings

6. Boolean() Convert parameters into Boolean values

Seven implicit type conversions Chinese method:

isNaN(), ++/—+/- (one dollar positive and negative), +, -*/%, && | | !, <> <= > =、==! =

1. isNaN() first calls the Number method with the parameters, and then compares it with NaN

2. ++/—+/- (one-yuan positive and negative) will follow The elements are converted into number type

3. + As long as there is a string type variable at the left and right ends of the plus sign, the variables on the other side will also be converted into String type

4. -*/% Convert to number type

5、&& | | ! Convert to Boolean type

6、<> <= >= Convert to number type

7, == != Convert to Boolean type

If an undefined variable is used directly, an error will be reported, but using typeof (variable) will not report an error, but will return a string "undefined"

Related recommendations:

Seven js data types to share

Detailed explanation of JavaScript data types

What are the specific basic data types in JS development

The above is the detailed content of Detailed explanation of JS data type examples. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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