JavaScript implicit type conversion steps and javascript steps

Source: Internet
Author: User

JavaScript implicit type conversion steps and javascript steps

Here, implicit type conversion is a conversion caused by =.

  1. If NaN exists, false is returned.
  2. If there is a Boolean, the Boolean is converted to a number.
  3. Check whether there are any strings. In three cases, the opposite 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 can be directly compared. Otherwise, false is returned.
  4. If it is a number, the other party is an object, and the object is compared with valueOf, all others will return false
  5. Null, undefined does not perform type conversion, but they are equal

This order must be memorized, which is frequently asked during interviews.

The following are some miscellaneous questions.

0 = undefined1 = true2 = {valueOf: function () {return 2} NaN = NaN 8 = undefined1 = undefined null = {toString: function () {return 2} 0 = null = 1 {toString: function () {return 1}, valueOf: function () {return [] }== 1

Summary

The above section describes the JavaScript implicit type conversion procedure. I hope it will help you. If you have any questions, please leave a message and I will reply to you in a timely manner. Thank you very much for your support for the help House website!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.