10 design flaws of JavaScript
JavaScript's design took only ten days. Moreover, the designer didn't want to design it initially, he just wanted to complete the task assigned by company. It is now a very powerful client side programming language used in almost all the websites. It's an excellent language, but it also has some flaws.
1. Not suitable for large projects
JavaScript doesn't have namespace, it's hard to be modular, there is no standard for putting codes in multiple source files. It allows defining functions with the same name, the function defined later will override the one defined previously, it's hard for method overloading.
2. Small standard library
JavaScript provides small standard function library.
3. null and undefined
null is one kind of object, it means the object is null; undefined is a data type, it means something undefined.
typeof null; // object
typeof undefined; // undefined
It's very easy to mess up these two, but the meaning is completely different.
var foo;
alert(foo == null); // true
alert(foo == undefined); // true
alert(foo === null); // false
alert(foo === undefined); // true
4. Global variable
JavaScript's global variables are visible in all modules, we can create global variable inside any function. This increases the complexity of program.
a = 1;
(function(){
b=2;
alert(a);
})(); // 1
alert(b); //2
5. The insertion of semi-colon at line end
Every statement in JavaScript should be ended with semi-colon. But if you forget to add semi-colon at the line end, the interpreter will not output the error, it will add the semi-colon at line end. Sometimes it may cause some errors difficult to find.
For example, the following function will not produce the expected result, the returned value is not an object, but undefined.
function(){
return
{
i=1
};
}
The reason is the interpreter will add a semi-colon at the end of return.
function(){
return;
{
i=1
};
}
6. + operator
+ as an operator has two meanings : can be used to add two numbers up or concatenate two strings.
alert(1+10); // 11
alert("1"+"10"); // 110
If one operand is string, the other operand is number, then the number will be converted to string automatically.
alert(1+"10"); // 110
alert("10"+1); // 101
This design increases the complexity of calculation.
7. NaN
NaN is a number, it means it overflows, it has some strange features:
NaN === NaN; //false
NaN !== NaN; //true
alert( 1 + NaN ); // NaN
8. The difference between array and object
Since JavaScript's array is also object, so if we want to find whether an object is an array, it's very difficult. Douglas Crockford provides the following code.
if ( arr &&
typeof arr === 'object' &&
typeof arr.length === 'number' &&
!arr.propertyIsEnumerable('length')){
alert("arr is an array");
}
9. == and ===
When two values are different, it will auto cast.
"" == "0" // false
0 == "" // true
0 == "0" // true
false == "false" // false
false == "0" // true
false == undefined // false
false == null // false
null == undefined // true
" \t\r\n" == 0 // true
So we recommend to use === whenever possible
10. The encapsulated object of primitive types
JavaScript has three primitive data types: string, number and boolean. They have respective value and function, it will create string object, number object and boolean object.
new Boolean(false);
new Number(1234);
new String("Hello World");
Some mess up
alert( typeof 1234); // number
alert( typeof new Number(1234)); // object
Author : coffeescript Source : http://blog.csdn.net/coffeescript/article/details/8212541
By clicking the "Mark as important" button, this article will be put to your important article list which you can find in "Amin->Article important list". Later when you want reread this article, it's easier for you to find it by checking the "Article important list".
Tags:JavaScript, Design flaw, Object Read(3814) Comment(3)
Previous : Microsoft's next generation OS Windows Blue may be free Next : File upload in PHP
::Related Articles
::Comment Zone
| Darkyen (abhishek@hingnikar.com) [Reply] | @ 2013-06-15 23:29:11 |
null is not an object, as typeof incorrectly suggests. For instance, (null instanceof Object) === false. And according to the ECMAScript spec, both null and undefined are primitive data types. | |
| GuncPinue (toquxolobys@hotmail.com) [Reply] | @ 2013-06-18 14:56:35 |
You are mistaken. I can prove it. Write to me in PM, we will discuss.
| |
::Comment
:: Other versions
No other versions available yet.
:: Recent articles
- The new Surface RT may use Qualcomm Snapdragon processor
- Fab CEO: Why we choose Tencent in China?
- Huawei is open to acquire Nokia
- HTML Email Guide
- Use of Erlang in WhatsApp
- Write high quality JavaScript and CSS with SublimeLinter
- Is Facebook developing RSS reader?
- About tmpfs
- Differences among Enter,F5 and Ctrl+F5 in webpage refresh
- China to expand 4G network across the country
- more>>
:: Most read
- TIOBE : C overtakes Java as the No.1 programming language
- Sony is to release PlayStation4 in 2015
- Which programming language should I learn first?
- Disposable Email address
- 5 Free Open Source Chat Applications For Developers
- Never ever touch a programmer
- Hacking Vs. Programming
- TIOBE : Where is that next big programming language?
- Multitasking vs multiprogramming
- Google is developing advanced programming technology to simplify Web application development
- more>>
:: Most commented
- Hacking Vs. Programming
- Which programming language should I learn first?
- Error handling style in C
- 10 controversial programming opinions?
- C vs Java Complete Comparison
- Google+ is sick
- Unix Philosophy
- Disposable Email address
- Should we use Abstract class or Interface?
- Some tricks on PHP session
- more>>
:: Contribute
Write article:: Find us

Hard time learning javascript, are we ?