10 things that are puzzling about JavaScript __java

Source: Internet
Author: User
Tags arithmetic numeric value

JavaScript, the world's most popular programming language, has been labeled as a nightmare for Web development designers, and while the real nightmare is the DOM API, the scripting language that has been exploited by a large number of developers and designers to augment their Web front end is now gaining weight, though, JavaScript still has a lot of confusing things to do. 1. It is named after Java, but not Java

It was originally called Mocha, then renamed to LiveScript, and finally decided to name JavaScript, according to historical records, Java's name and the cooperation between Netscape and Sun, in Exchange, Netscape in their popular browser created a Java Runtime. It is worth mentioning that the name of the introduction of nearly a joke, you know, LiveScript and Java in the client script has a hostile relationship.

Anyway, one of the things that people later have to clarify is that JavaScript has nothing to do with Java. 2. Null is an object.

Look at this code and it returns object.

This is really confusing, if NULL represents a null value, how can it be an object. To put it simply, it was the first version of JavaScript that was wrong, and it was even borrowed directly from Microsoft's JScript. 3. Nan!== nan

Nan, which represents a non-numeric value, however, the problem is that Nan is not equal to anything, not even to itself.

This is obviously not true, in fact, if you want to determine that a value is really NaN, you need to use the isNaN () function. 4. Global Variables

The dependency on global variables has always been considered the worst part of JavaScript (ECMA JavaScript 5 has removed global variables, see ECMA to eject the JavaScript 5-translator note). For simple pages, this doesn't matter, but complex pages, if it contains a lot of JavaScript scripts, you can hardly know where a global variable is declared, and if several global variables are accidentally duplicate names, an error is raised. 5. Browsers that have all been detected as Mozilla user-agent

It must be admitted that, in fact, it is not JavaScript's fault that browsers intentionally do it. For example, here are the results of using JavaScript to explore Safari:

Whether you notice the first word mozilla/5.0, why Safari is probed as Mozilla, although Safari has later corrected the problem, still can't explain why they are so misleading to developers. In fact, you'll find that most browsers set their User Agent to Mozilla, which is more of a strategy than it was 10 years ago.

The User Agent is a string that identifies the current browser identity, and the world's first browser, Mosaic, once flagged itself:

This makes sense, so when Netscape comes out, it retains the tradition of Mosaic and adds a part of the encryption method later.

So far, everything was fine until IE3 released, and when IE3 released, Netscape was at its zenith, and many servers and programs had deployed client-side probes to identify Netscape, which, although it is now debatable, is nothing. When IE first launches their User Agent flag, it looks like this:

This makes IE very passive because Netscape has been recognized by many servers, so developers simply want IE to be mistaken for Mozilla, and then add a separate tab for IE.

Today, almost all browsers follow IE's footsteps, marking themselves as Mozilla, which is probably a ripple effect. 6. Inconsistent function range

Refer to the following code:

Foo (bar.method) Returns the result differs because the method function is invoked as a Windows object, not as an object under bar. To solve this problem, we must call Bar.method () from the anonymous function passed. 7. Bitwise operator

JavaScript and Java have a lot in common, such as bit manipulation. &-| -or ^-XOR ~-not >>-Signed right Shift??? -Unsigned right shift <<-left shift

Look at the first & operator, use && should be more effective, because JavaScript and Java are not the same, JavaScript does not have integers, need to switch back and forth, so the conversion operation takes longer. 8. Too many types of null values

Values such as NULL, FALSE, and undefined are almost the same meaning, and the differences between them are confusing. 9. Arithmetic Problems

Although JavaScript contains a lot of arithmetic operations, you might want to run the following formula, ". 2+.4" should be equal to ". 6" is not, however, return is indeed "0.6000000000000001". JavaScript has some minor problems with decimal compute access.

Why is this. Simply put, because JavaScript uses the IEEE standard for binary floating-point operations, there is no problem with integer computations. 10. Inexplicable code Error

Look at the following two pieces of code:

They're supposed to be the same, except for the different positions, right. However, let's look at the following code:

If we take one of the

Into

Will cause an error because JavaScript has a feature that corrects code writing that it thinks is wrong, and it would be wise to insert a ";" after the word return.

This article source: http://net.tutsplus.com/tutorials/javascript-ajax/top-10-things-that-javascript-got-wrong/

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.