Javascript is dynamic, 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; and it can dynamically modify the properties of the object. There is no way to know the type of the variable at compile time, it can only be determined at runtime.
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.
What are static and dynamic languages?
Static language (strongly typed language)
Static language is a language in which the data type of the variable can be determined at compile time. Most static types The language requires that data types must be declared before variables can be used.
Dynamic language (weakly typed language)
Dynamic language is a language that determines the data type at runtime. There is no need for a type declaration before a variable is used. Usually the type of the variable is the type of the value to which it is assigned.
Is javascript a dynamic language?
Javascript is a dynamic language. JavaScript can dynamically modify the properties of an object. There is no way to know the type of the variable at compile time. It can only be determined at runtime.
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.
[Related recommendations: javascript learning tutorial]
##The advantages and disadvantages of static and dynamic languages
Advantages of statically typed languages:
1. Type mismatch errors can be found during compilation, and the editor can help us avoid them in advance while the program is running. There are some errors that 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. For more programming related knowledge, please visit:Programming Video! !
The above is the detailed content of Is javascript dynamic?. For more information, please follow other related articles on the PHP Chinese website!