Use (! + & Quot; \ v1 & quot;) determine whether it is an IE browser or a v1ie

Source: Internet
Author: User

Use (! + "\ V1") determines whether it is an Internet browser or a v1ie

I saw it on the yiniu blog (! + "\ V1"). Then, immediately find du Niang and find the answer.

It is actually a bug that uses ie.

In IE browser, "\ v" is not escaped and the result is "v"
In other browsers, "\ v" indicates a vertical tab (to some extent, it is equivalent to a space)

Therefore, the "\ v1" parsed by ie is "v1"
Other browsers resolve "\ v1" to "1"

Add "+" to the front to convert the string to a number.
Because ie considers "\ v1" as "v1", adding the plus sign in front of it cannot be converted into a number, which is NaN
Other browsers can be changed to 1

In js, numbers can be used for logical judgment, and 0 is false, and other numbers are true.
So! 1 = false, so all other browsers return false

Js returns false when encountering the following values: undefined, null, NaN, So ie! NaN = true

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.