A few small knowledge _javascript skills that can easily be bug-prone in JavaScript programming

Source: Internet
Author: User

JavaScript is one of the most popular programming languages today, but popular is also a side effect of the language's own features, no matter how wonderful the language is, thousands of programmers make a bunch of bugs every day. Don't laugh at others, maybe you are one of them.

To give you an example, here are a few short, fully valid JS clips (you can experiment on your console):

Copy Code code as follows:

typeof NaN = = ' Number '/true

Infinity = = 1/0//True

0.1 + 0.2 = = 0.3//False, same as front parenthesis

"3" + 1//' 31 '
"3"-1//2

Do you still believe in your own javascript?

1, JS the smallest value

Copy Code code as follows:

Number.min_value > 0; True

Number.min_value for JavaScript can be expressed as a minimum value of 5e-324, however, is the most nearly 0 of JS number

2. String connection

Copy Code code as follows:

("foo" + + "bar") = = "Foonan"//true
"Why I am" + typeof + ""//Why I am number

js resolves to "foo" + (+ "bar"), which will turn "bar" into a number

3. parseint function

Copy Code code as follows:

parseint (' 06 '); 6
parseint (' 08 '); 0 note, Google New version has been revised
parseint (null,) = = =/True

4, NULL is not object

Copy Code code as follows:

typeof Null//Object
Null instanceof Object//False

5. Return content

Copy Code code as follows:

function Myjson ()
{
Return
[
2
]
}

Myjson (); Undefined

Return must be returned on the same line

6, odd numbers.

Copy Code code as follows:

012 = =/False
' 012 ' = =/True
"3" + 1//' 31 '
"3"-1//2
0.1 + 0.2 = = 0.3//False
0.1 + 0.7 = = 0.8//False
0.2 + 0.7 = = 0.9//False
9999999999999999//10000000000000000
9999999999999999-1//10000000000000000
111111111111111111111//111111111111111110000

7, the weird parameters

Copy Code code as follows:

function Hello (what) {
Alert (arguments[0]); Vicky
what = "world";
Return "Hello," + arguments[0] + "!";
}

Hello ("Vicky"); "Hello, world!."

8, let the big-head equals sign

Copy Code code as follows:

Nan = = nan; False
[] = = false; True
"" = = false; True
NULL = = FALSE; False
[] == ! []//True

Window.window = = window/True
Window.window = = window//False, some browsers are true
window = document//True, some browsers are false

("0" && {}) = = 0//False
(0 && {}) = = 0/True
0 = "0"//True
[] = = 0//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.