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

Is javascript a dynamic weak language?

青灯夜游
青灯夜游Original
2021-10-25 12:08:011962browse

Javascript is a dynamic weak language. It is a literal scripting language, a dynamically typed, weakly typed, prototype-based language. In JavaScript, data types can be ignored. When assigning a value to a variable, you do not need to consider its type; the variable will not have a certain type until it is assigned a certain value.

Is javascript a dynamic weak language?

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

What are statically typed languages ​​and dynamically typed languages?

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.

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.

Advantages of dynamically typed languages:

The amount of code written is less and it looks more concise. Programmers can focus more on business logic above. 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.

What are strongly typed languages ​​and weakly typed languages?

1), Strongly typed language:

A language that forces data type definition. In other words, once a variable is assigned a certain data type, it will always be that data type if it is not cast. For example: if you define an integer variable a, then it is impossible for the program to treat a as a string type. A strongly typed definition language is a type-safe language.

2) Weakly typed language:

A language in which data types can be ignored. It is the opposite of a strongly typed definition language, in which a variable can be assigned values ​​of different data types.

Strongly typed definition languages ​​may be slightly slower than weakly typed definition languages, but the rigor brought by strongly typed definition languages ​​can effectively avoid many errors.

The manifestation of weak typing in javascript

The general rule is that the stronger the constraint, the less error-prone it is, but the more troublesome it is when writing a program. In JavaScript, because the constraints are relatively weak, this kind of error is prone to occur: the simplest example: var a =200;

var b ="1";
var c= a + b;

You may expect c to be 201, but in fact it is "2001", this Errors never occur in strongly typed languages. However, precisely because JavaScript does not have these constraints, it can easily concatenate numeric and string types.

[Recommended learning: javascript advanced tutorial]

The above is the detailed content of Is javascript a dynamic weak 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