First, Member operators
number.prototype.testfn=function () { Console.log ( this <0, this Span style= "color: #000000;" >.valueof ());} var num = -1;num.testfn (); // true-1 (). TESTFN (); // false 22.testFn (); // uncaught syntaxerror:invalid or unexpected token ( -1). TESTFN (); // true-1 -1..testfn (); // false 1 -1.2.testfn (); // false 1.2
The dot operator is prioritized as part of a numeric constant, and then is the object property accessor.
Second, even equal assignment value
var a = {N:1}; var b == a = {N:2}; Console.log (a.x); // undefined Console.log (b.x); // {N:2}
Exchange the order of the next hyphen, a = A.x = {N:2}; You can see that the result is the same, that the order does not affect the result.
Iii. Forced conversions
var areg =/^[a-z]+$/; areg.test (null); // trueareg.test (); // true
If the parameter of the test method is not a string, it is coerced into a string by an abstract ToString operation, so the string "null" and "undefined" are actually tested.
Iv. Communication of parameters
"1 2 3". Replace (/\d/g, parseint); // "1 NaN 3"
The actual calculations are [1, 0], [2, 2], [3, 4]
Why is adding attributes to the underlying type not an error but invalid?
var num = 1= 2; num.prop //undefined
Num.prop is equivalent to object (NUM). Prop, that is, we add attributes to a newly created object that has no relation to Num.
Have you seen any of these javascript traps?