Tell me, please, as a unit?
+!{}[0] // =1 Thank!
{}[0] → undefined !undefined → true, +true → 1The first thing that is used in this expression: Bracket notation - the ability to access the properties of objects using square brackets and a string key.
{}[0] - an attempt to take a property with the name 0 in an empty object. Since there is no such property, a regular undefined result will be obtained.
Further, the logical negation operator ( ! ) Is applied to the result ( undefined ). This operator returns applies the abstract method ToBoolean to the operand, and inverts the result.
As you can see from the table, for undefined the result is ToBoolean(undefined) → false , after inverting we get true .
Further, a unary operator + is applied to the result ( true ), which simply translates the result into a number. To do this, use the abstract function ToNumber.
As you can see from the table, for true, the result is ToNumber(true) → 1 .
Source: https://ru.stackoverflow.com/questions/633390/
All Articles
{}[0]-> undefined -> true ,+true-> 1 - Grundy+![][[]]- vp_arth[]. The main difference is that when using a dot, the property name must be a valid js identifier, and this imposes some restrictions, such as numbers, are not identifiers, so they cannot be used with a dot. On the other hand, the following entries are equivalent and the variable in them can be both an array and an object:a['toString'](),a.toString()- Grundy