Home > Back-end >  JavaScript data types
JavaScript data types

Time:12-02

Document types: professional technical summary literature;
Development tools and key technology:
Author: Yi Haitao; Grade: 2019; Time to write: on April 20, 2020

JavaScript data type
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ the development tools and key technology: Adobe Dreamweaver JavaScript
Author: Yi Haitao
Time to write: on April 20, 2020
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
Knowledge points list:
1. Literal, variables, identifiers
2. 6 types of data: JavaScript
Basic data types: String String type Number value type Boolean Boolean type
Null Null type Undefined Undefined type
Reference data type: Object type
3. The casts of JavaScript data
Mainly to transform other data types to String Number, Boolean,
1) converts the data type of the other type String
Method one:
- call is to convert the data types of the toString () method
- this method will not affect the original variable, it will be the result of the transformation to return
- note: null, and undefined the two values without the toString () method, if this method is invoked program complains
Method 2:
- call the String () function, and will be passed as a parameter to function conversion of data
- use the String () function when doing casts for Number Boolean actually
Is to call the toString () method, but to null, and undefined
Don't call the toString () method,
It will be null directly must change to "null" (string)
It will direct must change to "undefined" undefined (string)
(2) to convert other data types for the Number type
Use the Number () function
- string - & gt; Digital
1. If it is pure digital string can be directly converted into digital
2. If the content of the string contains non-numeric, converted to NaN
3. If the string is an empty string or a string, all Spaces are converted to 0
- Boolean value - & gt; For converting true must change to 1 false 0
- null - & gt; 0
- undefined - & gt; Digital NaN
The second way:
- this way specifically to deal with string type
- the parseInt () convert a string to an integer
- the parseFloat () convert a string to a floating point number
(3) other data types are converted to Boolean type
Use the Boolean () function
- digital - & gt; Boolean in addition to 0 and NaN is false, the rest are all true
- string - & gt; Boolean in addition to an empty string is false, the rest are all true
- null, and undefined will be converted to false
- object will be converted to true

You can use operator typeof detection data type
Grammar: typeof variable

CodePudding user response:

You can use operator typeof detection data types
  • Related