The first thing to know about JavaScript's automatic conversion is what type it needs, so JavaScript automatically passes the current type to the constructor of the required type to generate the required type
Guess 1:undefined is a class estimate in JavaScript (does not inherit object), and Null is a subclass of object, as is the case with an object-oriented approach
only 0 and empty strings equals false;undefined and Null objects are not equal to false objects, while null and undefined are equal
How does that make sense?
Conjecture 2: When you interact with a undefined object and other object objects, he converts himself to object (object (undefined);) and returns null
<script>
Alert (typeof (object (undefined) = = = = ' object ');
Alert (typeof undefined = = = ' object ');
Alert (String (Object (NULL) ===null));
Alert (String (undefined) ===null);//object Object
</script>
will return true and False,false,false
This conjecture seems wrong, the object constructor knowledge is insufficient (possibly without the constructor method with parameters) The string constructor is not knowledgeable enough to understand the return value
Although a null value cannot call the ToString method, it can be constructed using the string constructor. functions such as decodeURI, if passed in undefined or null, return "undefined" and "null" strings . This is easy to use wrong.
Alert (String (undefined)); "Undefined"
Alert (String (null)); //null
This estimate is just a special judgment in the constructor, meaningless.
There is a common denominator between false values and Null values, which is as the conditional branch of if, it is treated as false; Apply "!" True after Operation。
The special definition of the Boolean constructor, which is meaningless, cannot be verified whether the object object is converted first or is directly defined, a simple validation method is proposed to study
The arguments object is a new theory that is raised, about typeof () (only returns a string ...). Unable to validate inheritance property
<script>
Alert (typeof (false) = = = ' object '); False
Alert (typeof (0) = = = ' object '); False
</script>
Total conjecture error, all errors, re-collection of knowledge:
Undefined object is the engine according to certain conditions and judgments, the reference point to the past, and then other classes to do some catch ex operation, the estimated implementation method is this
In ECMAScript, the physical representation of an object cannot be accessed, and only references to the object can be accessed. Every time you create an object, it is stored in a variable and is a reference to that object, not the object itself.
Only the = = = operation can be used to test whether a value is undefined, because the = = operator considers the undefined value equivalent to null.
Note: null means no value, and undefined represents an undeclared variable, or a variable that has been declared but not assigned a value, or an object property that does not exist.
An object-oriented language requires the developer to provide four basic capabilities:
- Encapsulation-the ability to store relevant information (regardless of data or method) in an object
- Aggregation-the ability to store an object within another object
- Inheritance-the ability to get properties and methods of a class by another class (or classes)//This is too fake, the top-level attribute does not inherit object, and the object's re-understanding is just a design pattern that JavaScript joins for object-oriented
- Polymorphism-Ability to write functions or methods that can run in multiple ways
ECMAScript supports these requirements and can therefore be viewed as object-oriented.
Early binding (early binding) refers to defining its properties and methods before instantiating an object, so that the compiler or interpreter can convert machine code ahead of time. In languages such as Java and Visual Basic, with early binding, IntelliSense can be used in the development environment (that is, the ability to provide developers with a list of properties and methods in objects). ECMAScript is not a strongly typed language, so early binding is not supported.
Late binding (late binding), on the other hand, refers to the type of object that the compiler or interpreter does not know before it runs. With late binding, you do not need to check the object's type, just check whether the object supports properties and methods. All variables in the ECMAScript are in late binding methods. This allows a large number of object operations to be performed without any penalty.
In short, JavaScript top-level elements are encapsulated into 8 categories, and there is no inheritance relationship. Then write 8 times for example ToString.
Then the realization and transformation of these judgments is nothing more than the specific judgments in various construction methods.
In ECMAScript, the equals sign is represented by a double equal sign (= =), which returns True when and only if two operands are equal. A non-equal sign is represented by an exclamation mark plus an equals sign (! =), which returns True when and only if the two operands are not equal. To determine whether the two operands are equal, both operators perform type conversions.
The rules for performing type conversions are as follows:
- If one of the operands is a Boolean value, convert it to a numeric value before checking for equality. False converts to 0,true to 1.
- If one operand is a string and the other is a number, try converting the string to a number before checking for equality.
- If one operand is an object and the other is a string, try to convert the object to a string before checking for equality.
- If one operand is an object and the other is a number, try converting the object to a number before checking for equality.
The operator also adheres to the following rules when comparing:
- The value null and undefined are equal.
- When checking for equality, null and undefined cannot be converted to other values.
- If an operand is NaN, the equal sign returns false, and the non-equal sign returns TRUE.
- If the two operands are objects, then their reference values are compared. If two operands point to the same object, then the equals sign returns TRUE, otherwise two operands are not equal. //Well, I'm just saying it.
The company server is broken, bored. Analyzing the null and false values of JavaScript under the object-oriented method