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 objectsconstructsIt’s not going to change
  • Of all objectsPrototype chainAll contain objectPrototype chain
  • In addition, the prototype chain judgment of all objects is the same as before the cast. What was the originalconstructsGenerated, now on which constructPrototype chainIs true, for exampleoNumberIt was instantiated originallyNumberObject, so the inclusion of the prototype chain will only be included in the determinationNumberWhen 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

    • originallyobjectThe display for[object Object]
    • originallyStringThere is no change in the display of
    • originallyBooleanIs displayed as a Boolean value of type string
    • originallyNumberIs displayed as the string Number value
    • originallyArrayIs displayed as a string Array value. Each value in the Array is concatenated with a comma
    • originallyDateIs displayed as the default date type (showing all the time information and the occasional area and so on)
  • __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
    • originallyobjectThe display forNaN
    • originallyStringThere is no change in the display of
    • originallyBooleanThe display for1
    • originallyNumberThe display for68
    • originallyArrayThe display forNaN
    • originallyDateThe 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.
  • Of all objects__proto__All become[Number: 0]
  • Of all objectsconstructsAll become[Function: Number]
  • Of all objectsPrototype chainAnd six data typesPrototype chainDon’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 passObjectorArrayAfter a cast, it can be found on the prototype chainobjectConstruct the body prototype chain
  • All objects passStringorDateAfter a type cast, the object’s__proto__Are all[String: '']The constructor of the object becomes[Function: String].
  • In addition toObjectandArrayAfter a type cast, the value of all objectsPrototype chainAnd six data typesPrototype chainDon’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