This time I will bring you the implicit type conversion of JSDetailed explanation, what are the notes of implicit type conversion of JS, the following is a practical case, let’s take a look .
The implicit type conversion mentioned here is the conversion caused by ==.
If NaN exists, always return false
Check again to see if there is a Boolean, if there is a Boolean, convert the Boolean into a number
Then check to see if there is a string. There are three situations. The other party is an object, and the object is converted using toString; the other party is a number, and the string is converted to a number; If it is a string, compare it directly; if it is a number, it will return false
If it is a number and the other party is an object, the object will be compared with valueOf, and if it is anything else, it will return false
null, undefined will not perform type conversion, but they are equal
This sequence must be memorized, which is often asked during interviews.
Here are some miscellaneous questions, do it yourself
0 == undefined 1 == true 2 == {valueOf: function(){return 2}} NaN == NaN 8 == undefined 1 == undefined null == {toString: function(){return 2}} 0 == null null == 1 { toString:function(){ return 1 } , valueOf:function(){ return [] }} == 1
I believe you have mastered the method after reading the case in this article, please pay attention for more exciting things Other related articles on php Chinese website!
Recommended reading:
##How to use the $http service in angular
Several ways of AngularJS dependency injection
Detailed explanation of the use of angular routing ui-router
The above is the detailed content of Detailed explanation of implicit type conversion in JS. For more information, please follow other related articles on the PHP Chinese website!