I am small and live in Wuhan, do two years of new media, ready to use 6 months time to switch to the front end of the industry.
Lesson Objective for today
Yesterday, I learned object deconstruction based on search, and then today IS ready to learn __proto__ and prototype mentioned in many objects, so today’s practical learning JS type conversion, is a day for learning, come on, small and !!!!
Today is mainly the actual learning String, Number, Boolean, Object, the Date, the exchange of Array type
Cast result
Object cast
- The original value
The instance name | The original value | Method of use |
---|---|---|
ooo | {} | ooo.constructor |
ooBool | [Boolean: true] | ooBool.constructor |
ooNum | [Number: 68] | ooNum.constructor |
ooString | [String: ‘hello world’] | ooString.constructor |
ooArray | [ ‘demo’, ‘little’, ‘you’ ] | ooArray.constructor |
ooDate | Tue May 20 2020 22:32:04 | ooDate.constructor |
- constructor
The instance name | constructs | Method of use |
---|---|---|
ooo | [Function: Object] | ooo.constructor |
ooBool | [Function: Boolean] | ooBool.constructor |
ooNum | [Function: Number] | ooNum.constructor |
ooString | [Function: String] | ooString.constructor |
ooArray | [Function: Array] | ooArray.constructor |
ooDate | [Function: Date] | ooDate.constructor |
__proto__
The instance name | The default value | Method of use |
---|---|---|
ooo | {} | ooo.__proto__ |
ooBool | [Boolean: false] | ooBool.__proto__ |
ooNumber | [Number: 0] | ooNum.__proto__ |
ooString | [String: ”] | ooString.__proto__ |
ooArray | [] | ooArray.__proto__ |
ooDate | Date {} | ooDate.__proto__ |
- Whether the instance Object’s prototype chain contains an Object’s prototype chain
Through varName instanceof Object, ooo, ooBool ooNum, ooString, ooArray and oDate constructs are true.
- Whether the instance object prototype chain contains the prototype chain of String
The instance name | Attribute values | Method of use |
---|---|---|
ooo | false | ooo instanceof String |
ooBool | false | ooBool instanceof String |
ooNumber | false | ooNum instanceof String |
ooString | true | ooString instanceof String |
ooArray | false | ooArray instanceof String |
ooDate | false | ooDate instanceof String |
- Whether the instance object stereotype chain contains a Boolean stereotype chain
The instance name | Attribute values | Method of use |
---|---|---|
ooo | false | ooo instanceof Boolean |
ooBool | true | ooBool instanceof Boolean |
ooNumber | false | ooNum instanceof Boolean |
ooString | false | ooString instanceof Boolean |
ooArray | false | ooArray instanceof Boolean |
ooDate | false | ooDate instanceof Boolean |
- Whether the instance object stereotype chain contains the stereotype chain of Number
The instance name | Attribute values | Method of use |
---|---|---|
ooo | false | ooo instanceof Number |
ooBool | false | ooBool instanceof Number |
ooNumber | true | ooNum instanceof Number |
ooString | false | ooString instanceof Number |
ooArray | false | ooArray instanceof Number |
ooDate | false | ooDate instanceof Number |
- Whether the instance object prototype chain contains the Array prototype chain
The instance name | Attribute values | Method of use |
---|---|---|
ooo | false | ooo instanceof Array |
ooBool | false | ooBool instanceof Array |
ooNumber | false | ooNum instanceof Array |
ooString | false | ooString instanceof Array |
ooArray | true | ooArray instanceof Array |
ooDate | false | ooDate instanceof Array |
- Whether the prototype chain of the instance object contains the prototype chain of Date
The instance name | Attribute values | Method of use |
---|---|---|
ooo | false | ooo instanceof Date |
ooBool | false | ooBool instanceof Date |
ooNumber | false | ooNum instanceof Date |
ooString | false | ooString instanceof Date |
ooArray | false | ooArray instanceof Date |
ooDate | true | ooDate instanceof Date |
String cast
- The original value
The instance name | The original value | Method of use |
---|---|---|
soo | [object Object] | soo.constructor |
soBool | true | soBool.constructor |
soNum | 68 | soNum.constructor |
soString | hello world | soString.constructor |
soArray | demo,little,you | soArray.constructor |
soDate | Tue May 20 2020 22:32:04 | soDate.constructor |
- constructor
Through varName constructor, soo, soBool soNum, soString, soArray and soDate constructs are Function: String.
__proto__
Through varName __proto__, soo, soBool soNum, soString, soArray and soDate prototypes are [String: “‘].
- Whether the instance Object’s prototype chain contains an Object’s prototype chain
Through varName instanceof Object, soo, soBool soNum, soString, soArray and soDate contains the Object’s prototype chain are false.
- Whether the instance object prototype chain contains the prototype chain of String
Through varName instanceof String, soo, soBool soNum, soString, soArray and soDate contains String prototype chain are false.
- Whether the instance object stereotype chain contains a Boolean stereotype chain
Through varName instanceof Boolean, soo, soBool soNum, soString, soArray and soDate contains Boolean prototype chain are false.
- Whether the instance object stereotype chain contains the stereotype chain of Number
Through varName instanceof Number, soo, soBool soNum, soString, soArray and soDate does it include the prototype chain Number are false.
- Whether the instance object prototype chain contains the Array prototype chain
Through varName instanceof Array, soo, soBool soNum, soString, soArray and soDate contains an Array of prototype chain are false.
- Whether the prototype chain of the instance object contains the prototype chain of Date
Through varName instanceof Date, soo, soBool soNum, soString, soArray and soDate does it include the Date the prototype chain are false.
Boolean cast
- The original value
Through varName, boo, boBool boNum, boString, boArray and boDate original values are true.
- constructor
Through varName constructor, boo, boBool, boNum, boString, boArray and boDate constructs are Function: Boolean.
__proto__
Through varName __proto__, boo, boBool boNum, boString, boArray and boDate prototypes are Boolean: false.
- Whether the instance Object’s prototype chain contains an Object’s prototype chain
Through varName instanceof Object, boo, boBool boNum, boString, boArray and boDate contains the Object’s prototype chain are false.
- Whether the instance object prototype chain contains the prototype chain of String
Through varName instanceof String, boo, boBool boNum, boString, boArray and boDate contains String prototype chain are false.
- Whether the instance object stereotype chain contains a Boolean stereotype chain
Through varName instanceof Boolean, boo, boBool boNum, boString, boArray and boDate contains Boolean prototype chain are false.
- Whether the instance object stereotype chain contains the stereotype chain of Number
Through varName instanceof Number, boo, boBool boNum, boString, boArray and boDate does it include the prototype chain Number are false.
- Whether the instance object prototype chain contains the Array prototype chain
Through varName instanceof Array, boo, boBool boNum, boString, boArray and boDate contains an Array of prototype chain are false.
- Whether the prototype chain of the instance object contains the prototype chain of Date
Through varName instanceof Date, boo, boBool boNum, boString, boArray and boDate does it include the Date the prototype chain are false.
Number cast
- The original value
The instance name | The original value | Method of use |
---|---|---|
noo | NaN | noo.constructor |
noBool | 1 | noBool.constructor |
noNum | 68 | noNum.constructor |
noString | NaN | noString.constructor |
noArray | NaN | noArray.constructor |
noDate | 1589898724740 | noDate.constructor |
- constructor
Through varName constructor, noo, noBool noNum, noString, noArray and noDate constructs are [Function: Number].
__proto__
Through varName __proto__, noo, noBool noNum, noString, noArray and noDate prototypes are (Number: 0).
- Whether the instance Object’s prototype chain contains an Object’s prototype chain
Through varName instanceof Object, noo, noBool noNum, noString, noArray noDate and does it include the Object’s prototype chain are false.
- Whether the instance object prototype chain contains the prototype chain of String
Through varName instanceof String, noo, noBool noNum, noString, noArray noDate and does it include String prototype chain are false.
- Whether the instance object stereotype chain contains a Boolean stereotype chain
Through varName instanceof Boolean, noo, noBool noNum, noString, noArray noDate and does it include Boolean prototype chain are false.
- Whether the instance object stereotype chain contains the stereotype chain of Number
Through varName instanceof Number, noo, noBool noNum, noString, noArray noDate and does it include the prototype chain Number are false.
This is weird
- Whether the instance object prototype chain contains the Array prototype chain
Through varName instanceof Array, noo, noBool noNum, noString, noArray noDate and contains an Array of prototype chain are false.
- Whether the prototype chain of the instance object contains the prototype chain of Date
Through varName instanceof Date, noo, noBool noNum, noString, noArray noDate and does it include the Date the prototype chain are false.
Array cast
- The original value
The instance name | The original value | Method of use |
---|---|---|
aoo | ({}) | aoo.constructor |
aoBool | [ [Boolean: true] ] | aoBool.constructor |
aoNum | [ [Number: 68] ] | aoNum.constructor |
aoString | [ [String: ‘hello world’] ] | aoString.constructor |
aoArray | [ [ ‘demo’, ‘little’, ‘you’ ] ] | aoArray.constructor |
aoDate | [Tue May 20 2020 22:32:04 ] | aoDate.constructor |
- constructor
Through varName constructor, aoo aoBool, aoNum, aoString, aoArray and aoDate constructs are Function: Array.
__proto__
Through varName __proto__, aoo aoBool, aoNum, aoString, aoArray and aoDate prototype is [].
- Whether the instance Object’s prototype chain contains an Object’s prototype chain
Through varName instanceof Object, aoo aoBool, aoNum, aoString, aoArray and aoDate contains the Object’s prototype chain are false.
- Whether the instance object prototype chain contains the prototype chain of String
Through varName instanceof String, aoo aoBool, aoNum, aoString, aoArray and aoDate contains String prototype chain are false.
- Whether the instance object stereotype chain contains a Boolean stereotype chain
Through varName instanceof Boolean, aoo aoBool, aoNum, aoString, aoArray and aoDate contains Boolean prototype chain are false.
- Whether the instance object stereotype chain contains the stereotype chain of Number
Through varName instanceof Number, aoo aoBool, aoNum, aoString, aoArray and aoDate does it include the prototype chain Number are false.
- Whether the instance object prototype chain contains the Array prototype chain
Through varName instanceof Array, aoo aoBool, aoNum, aoString, aoArray and aoDate contains an Array of prototype chain are true.
- Whether the prototype chain of the instance object contains the prototype chain of Date
Through varName instanceof Date, aoo aoBool, aoNum, aoString, aoArray and aoDate does it include the Date the prototype chain are false.
Date cast
- The original value
Through varName, scooby-doo, doBool doNum, doString, doArray and doDate original values are Tue May 20, 2020 22:35:18.
- constructor
Through varName constructor, scooby-doo, doBool, doNum, doString, doArray and doDate constructs are Function: String.
This is weird
__proto__
Through varName __proto__, scooby-doo, doBool, doNum, doString, doArray and doDate prototypes are [String: “‘].
- Whether the instance Object’s prototype chain contains an Object’s prototype chain
Through varName instanceof Object, scooby-doo, doBool doNum, doString, doArray and doDate contains the Object’s prototype chain are false.
- Whether the instance object prototype chain contains the prototype chain of String
Through varName instanceof String, scooby-doo, doBool doNum, doString, doArray and doDate contains String prototype chain are false.
- Whether the instance object stereotype chain contains a Boolean stereotype chain
Through varName instanceof Boolean, scooby-doo, doBool doNum, doString, doArray and doDate contains Boolean prototype chain are false.
- Whether the instance object stereotype chain contains the stereotype chain of Number
Through varName instanceof Number, scooby-doo, doBool doNum, doString, doArray and doDate does it include the prototype chain Number are false.
- Whether the instance object prototype chain contains the Array prototype chain
Through varName instanceof Array, scooby-doo, doBool doNum, doString, doArray and doDate contains an Array of prototype chain are false.
- Whether the prototype chain of the instance object contains the prototype chain of Date
Through varName instanceof Date, scooby-doo, doBool doNum, doString, doArray and doDate does it include the Date the prototype chain are false.
conclusion
Object Forcible type conversion
- Not all modified object content
- Of all objects
__proto__
It’s not going to change - Of all objects
constructs
It’s not going to change - Of all objects
Prototype chain
All contain objectPrototype chain
- In addition, the prototype chain judgment of all objects is the same as before the cast. What was the original
constructs
Generated, now on which constructPrototype chain
Is true, for exampleoNumber
It was instantiated originallyNumber
Object, so the inclusion of the prototype chain will only be included in the determinationNumber
When we construct the prototype chaintrue
, for the judgment of the prototype chain of the remaining four types of structural bodies, all arefalse
.
String cast
-
All objects display their content differently
- originally
object
The display for[object Object]
- originally
String
There is no change in the display of - originally
Boolean
Is displayed as a Boolean value of type string - originally
Number
Is displayed as the string Number value - originally
Array
Is displayed as a string Array value. Each value in the Array is concatenated with a comma - originally
Date
Is displayed as the default date type (showing all the time information and the occasional area and so on)
- originally
-
__proto__ of all objects is changed to [String: “]
-
All object constructors become [Function: String]
-
The prototype chains of all objects do not match the prototype chains of the six data types
Boolean Cast type
- The contents of all objects are changed to true
- Of all objects
__proto__
All become[Boolean: false]
- The constructors of all objects become
[Function: Boolean]
- The prototype chains of all objects do not match the prototype chains of the six data types
Number Forcible type conversion
- All objects display their content differently
- originally
object
The display forNaN
- originally
String
There is no change in the display of - originally
Boolean
The display for1
- originally
Number
The display for68
- originally
Array
The display forNaN
- originally
Date
The display for1589898724740
, the timestamp corresponding to the current date (Tue May 20 2020 22:35:18), the current date is from January 1, 2070Number of milliseconds
, timestamp /(10006060*24), the number of days between the current date and January 1, 2070.
- originally
- Of all objects
__proto__
All become[Number: 0]
- Of all objects
constructs
All become[Function: Number]
- Of all objects
Prototype chain
And six data typesPrototype chain
Don’t match
Array mandatory type conversion
-
[[‘demo’, ‘little’, ‘you’]] [[‘demo’, ‘little’, ‘you’]]
-
__proto__ of all objects is changed to []
-
All object constructors become [Function: Array]
-
All object prototype chains contain both object prototype chains and Array prototype chains
-
The prototype chains for all objects do not match those for the remaining four data types
Date cast
-
Tue May 20 2020 22:35:18 Default date type (showing all time information and time zones etc.)
-
__proto__ of all objects is changed to [String: “]
-
All object constructors become [Function: String]
-
The prototype chains of all objects do not match the prototype chains of the six data types
Common ground for casting
- All objects pass
Object
orArray
After a cast, it can be found on the prototype chainobject
Construct the body prototype chain - All objects pass
String
orDate
After a type cast, the object’s__proto__
Are all[String: '']
The constructor of the object becomes[Function: String]
. - In addition to
Object
andArray
After a type cast, the value of all objectsPrototype chain
And six data typesPrototype chain
Don’t match
Summary of today’s lesson
Today the mood
Today is mainly study the String, Number, Boolean, Object, the Date, the Array type conversion, feel the several types of into some trouble, feel want to deepen the understanding in practice after ~, the contents of this wish tomorrow learn more ~ ~ ~ ~
This article is formatted using MDNICE