-
JavaScript was designed to “look similar enough to Java, but simpler enough to make it easy for non-professional web authors to pick up”, so 34-year-old programmer Brendan Eich created it in just 10 days. Because the design time was too short, some of the details of the language were not carefully considered, resulting in a long time later, Javascript written programs chaotic. If Brendan Eich had foreseen a future in which this language would be the number one language on the Internet, with millions of learners worldwide, would he have taken a little more time?
-
Design features of JavaScript: JavaScript combines both functional and object-oriented programming in a way that has never been done before, and it remains the only language in the world that uses the Prototype inheritance model.
-
JavaScript design flaws:
- Not suitable for developing large programs: JS has no namespace and is difficult to modularize.
- Very small standard library
- Null and undefined NULL is a type of object, meaning that the object is empty. Undefined is a data type, meaning undefined. The two have different but confusing meanings, and null is almost useless in programming practice and should not be designed at all.
- Global variables are difficult to control JS global variables are visible in all modules, any function can generate global variables inside, which greatly increases the complexity of the program.
- Automatic insertion of end-of-line semicolons
- The plus operator +, as an operator, has two meanings. It can represent the sum of numbers or the concatenation of characters. Such a design unnecessarily increases the complexity of the operation, and a separate concatenated operator could have been designed.
- NaN is a number that indicates that the interpreter is out of its limits, and rather than being designed this way, the interpreter should simply report an error.
- An array is also an object, so it is difficult to tell whether an object is an array or not.
- == and === == are used to determine whether two values are equal or not. When two values are of different types, automatic conversion occurs, resulting in very strange results. Therefore, the “===” (accurate judgment) comparator should be used in all cases.
- The primitive wrapper object JS has three basic data types: string, number, and Boolean. They all have constructors that generate string objects, number objects, and Booleans. However, objects corresponding to primitive data types are of little use and can cause a lot of confusion.