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

Is javascript a dynamic language?

青灯夜游
青灯夜游Original
2021-10-09 17:57:011778browse

Javascript is a dynamic language. It is a dynamically typed, weakly typed, prototype-based language. In JavaScript, when assigning a value to a variable, you do not need to consider its type. Therefore, it is a typical dynamically typed language.

Is javascript a dynamic language?

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

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.

And 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.

JavaScript is a dynamically typed, weakly typed, prototype-based language.

The difference between statically typed languages ​​and dynamically typed languages

The advantage of statically typed languages ​​is that type mismatches can be discovered at compile time. Errors, the editor can help us avoid some errors that may occur during the running of the program in advance. Secondly, 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.

The shortcomings of statically typed languages ​​are that they first force programmers to write programs according to strong contracts and specify data types for each variable. In the final analysis, it is just a means to assist us in writing high-reliability programs, rather than a way to write programs. Purpose, after all, the purpose of most people writing programs is to complete requirements and deliver production. Secondly, 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.

The advantage of a dynamically typed language is that less code is written 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.

The disadvantage of dynamically typed languages ​​is that the type of variables cannot be guaranteed, so type-related errors may occur during the runtime of the program.

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 learning: javascript advanced 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