implicit conversion

js objects are divided into local objects and host objects.

 

The so-called local objects, also known as built-in objects

    Array Object Function Boolean

The so-called host object is the environment or object that has a host

   BOM:window Navigator Screen History Location

   DOM:Document Element Attribute Event

 

 Both local objects inherit toString() and valueOf() methods

 toString(): convert string

 valueOf(): turn the original value (number)

 

1. Compare the size between local objects : follow the principle of array<string[toString()]<number[valueOf()]

That is, if any two are compared, the priority of the right side is higher than that of the left side . When comparing, the left side will be implicitly converted to the right side and then compared.

Array vs String: Array to String

Arrays vs Numbers: Arrays are first converted to strings and then to numbers

String vs Number: String to Number

When comparing with Boolean values, both sides are converted into numbers for comparison [true==>1 false==>0]

Arrays vs Booleans: Arrays are first converted to strings and then converted to numbers, and Booleans are converted directly to numbers

String vs Boolean: Strings are converted to numbers, and Booleans are directly captured as numbers

Number vs Boolean: Boolean to Number

 

2. Add (+) operation between local objects

String + Number: Number will be converted to string

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325573222&siteId=291194637