Home > Web Front-end > JS Tutorial > body text

A brief analysis of JavaScript implicit type conversion steps

亚连
Release: 2018-05-29 18:04:21
Original
2129 people have browsed it

Implicit type conversion is the conversion caused by ==. Let me share with you the JavaScript implicit type conversion steps through this article. Friends who are interested can take a look.

The implicit type conversion mentioned here, It is the conversion caused by ==.

  1. If NaN exists, always return false

  2. Check again to see if there is a Boolean, if there is a Boolean, convert the Boolean into a number

  3. 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; the other party is a string, and compared directly; otherwise, false is returned

  4. If it is a number and the other party is an object, the object will be compared with valueOf, otherwise it will return false

  5. null, undefined will not perform type conversion, but They are both equal

This order must be memorized by rote. This is often asked during interviews.

The following are some miscellaneous questions, you can 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
Copy after login

The above is what I compiled for everyone. I hope it will be helpful to everyone in the future.

Related articles:

Postman simulates the method of sending a request with token

A brief discussion on Postman’s solution to the problem of passing token parameters

postman json springmvc test batch add instance

The above is the detailed content of A brief analysis of JavaScript implicit type conversion steps. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!