Home  >  Article  >  Web Front-end  >  Is javascript a dynamic language?

Is javascript a dynamic language?

藏色散人
藏色散人Original
2021-10-14 15:05:271931browse

Javascript is a dynamic language, a dynamically typed, weakly typed, prototype-based language; JavaScript can respond to user input without going through the Web server.

Is javascript a dynamic language?

The operating environment of this article: windows7 system, javascript version 1.8.5, Dell G3 computer.

Is javascript a dynamic language?

JavaScript is a dynamically typed, weakly typed, prototype-based language. Its interpreter is called the JavaScript engine, which is part of the browser and is widely used in client-side scripting languages. It was first used on HTML web pages to add dynamic functions to HTML web pages.

JavaScript script language has the following characteristics:

(1) Script language. JavaScript is an interpreted scripting language. Languages ​​such as C and C are compiled first and then executed, while JavaScript is interpreted line by line during the running of the program.

(2) Based on objects. JavaScript is an object-based scripting language that can not only create objects but also use existing objects.

(3)Simple. The JavaScript language uses weakly typed variable types and does not impose strict requirements on the data types used. It is a scripting language based on Java's basic statements and controls, and its design is simple and compact.

(4)Dynamic. JavaScript is an event-driven scripting language that can respond to user input without going through a Web server. When visiting a web page, JavaScript can directly respond to these events when the mouse is clicked, moved up or down, or moved in the window.

(5) Cross-platform. The JavaScript scripting language does not depend on the operating system and only requires browser support. Therefore, after writing a JavaScript script, it can be brought to any machine for use, provided that the browser on the machine supports the JavaScript scripting language. JavaScript has been supported by most browsers. [6] Unlike server-side scripting languages, such as PHP and ASP, JavaScript is mainly used as a client-side scripting language to run on the user's browser and does not require server support. Therefore, in the early days, programmers preferred JavaScript to reduce the burden on the server, but at the same time it also brought about another problem, security.

As servers become more powerful, although programmers prefer scripts running on the server to ensure security, JavaScript is still popular for its cross-platform and easy-to-use advantages. At the same time, some special functions (such as AJAX) must rely on JavaScript to be supported on the client side.

Programming languages ​​can be roughly divided into two categories according to data types, one is statically typed language, and the other is dynamically typed language.

The type of variables in statically typed languages ​​is determined at compile time, while the variable types in dynamically typed languages ​​will not have a certain type until the variable is assigned a certain value when the program is running.

Advantages of statically typed languages:

1. Type mismatch errors can be found during compilation. The editor can help us avoid errors during program runtime in advance. Some errors may occur.

2. If the data type is clearly specified in the program, the compiler can also perform some optimization work on the program based on this information to improve the execution speed of the program.

Disadvantages of statically typed languages:

1. Force programmers to write programs according to strong contracts and specify data types for each variable. In the final analysis, they only help us write reliable programs. It is a means of high-performance programming, not the purpose of writing a program. After all, the purpose of most people writing programs is to complete the requirements and deliver production.

2. Type declarations will also add more code. During the program writing process, these details will distract the programmer's energy from thinking about business logic.

Advantages of dynamically typed languages:

The amount of code written is less and it looks more concise. Programmers can focus more on business logic. . Although not distinguishing between types can make the program difficult to understand in some cases, overall, the smaller the amount of code and the more focused on logical expression, the more helpful it is for reading the program.

Disadvantages of dynamically typed languages:

The type of variables cannot be guaranteed, so type-related errors may occur during the runtime of the program. It's like buying a pack of beef chili strips at the store, but you don't know whether they taste like beef until you actually eat them.

Javascript is a dynamic language. In JavaScript, when assigning a value to a variable, there is no need to consider its type. Therefore, JavaScript is a typical dynamically typed language.

The tolerance of dynamically typed languages ​​to variable types brings great flexibility to actual coding. Without type checking, we can try to call any method on any object, regardless of whether it was designed to have that method.

Recommended study: "javascript basic tutorial"

The above is the detailed content of Is javascript a dynamic language?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn