JavaScript was first designed and implemented in 1995 by Brendan Eich of Netscape in the Netscape Navigator browser. Because Netscape worked with Sun, Netscape management wanted it to look like Java, hence the name JavaScript.

In May 1995, Netscape decided that the web scripting language of the future would have to “look similar enough to Java,” but be simpler enough to make it accessible to non-professional web authors. Brendan Eich was designated as the designer of this “simplified Version of the Java language.”

Design ideas

  1. Learn from the basic syntax of C language;
  2. Using the Java language for data types and memory management;
  3. Using Scheme language to elevate functions to the status of “first class”;
  4. Reference Self language, using prototype – based inheritance mechanism.

It’s a one-night stand between C and Self.

The main function

  1. Embed dynamic text in HTML pages.
  2. Responds to browser events.
  3. Read and write HTML elements.
  4. Validate data before it is submitted to the server.
  5. Detect the visitor’s browser information. Control cookies, including creation and modification.
  6. Server-side programming based on Node.js technology.

10 Design Flaws with Javascript

1. Not suitable for developing large programs

Javascript has no namespace and is difficult to modularize; There is no specification for how to distribute code across multiple files; Allows for duplicate definitions of functions with the same name, with the latter overwriting the previous, making modular loading difficult.

2. Very small standard libraries

The standard library of functions provided by Javascript is very small and can only do a few basic operations, with many functions lacking.

3. The null, and undefined

Null is a type of object, meaning that the object is empty. Undefined is a data type, meaning undefined.

4. Global variables are difficult to control

Javascript global variables, visible in all modules; Global variables can be generated inside any function, which greatly increases the complexity of the program.

5. Automatically insert semicolons at the end of lines

All Javascript statements must end with a semicolon. However, if you forget to add a semicolon, the interpreter does not report an error, but automatically adds a semicolon for you. Sometimes, this leads to errors that are hard to spot.

6. The plus operator

As an operator, the + sign has two meanings. It can represent the sum of numbers or the concatenation of characters.

7. NaN

NaN is a number that indicates that the interpreter has exceeded its limits. It has some very strange properties:

NaN === NaN; //false NaN ! == NaN; //true alert( 1 + NaN ); // NaNCopy the code

8. Distinction between arrays and objects

Since Javascript arrays are objects, it can be tricky to tell whether an object is an array or not.

9. = = and = = =

== is used to determine whether two values are equal. When two value types are different, an automatic conversion occurs, and the result is very counterintuitive.

"" == "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 // trueCopy the code

Therefore, it is recommended to use the “===” (exact judgment) comparator at all times.

  1. Wrapper object of basic type

Javascript has three basic data types: strings, numbers, and Booleans. They all have constructors that generate string objects, number objects, and Booleans.

  new Boolean(false);

  new Number(1234);

  new String("Hello World");
Copy the code

The object types that correspond to the base data types are of little use but of great confusion.

  alert( typeof 1234); // number

  alert( typeof new Number(1234)); // object
Copy the code