Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the type of javascript?

2025-01-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces "what type is javascript". In daily operation, I believe many people have doubts about what type of javascript is. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful for you to answer the doubts about "what type is javascript?" Next, please follow the editor to study!

Javascript is a weak type. Javascript is a language in which data types can be ignored, and a variable can assign values of different data types. Javascript allows implicit conversions of variable types, mandatory type conversions, etc., such as automatic conversion of strings and values, while strongly typed languages generally do not allow this.

The operating environment of this tutorial: windows7 system, javascript1.8.5 version, Dell G3 computer.

Strongly typed definition language and weak typed definition language 1) strongly typed definition language:

The language that forces the definition of the data type. That is, once a variable is assigned a data type, it will always be that data type if it is not cast. For example: if you define an integer variable a, it is impossible for the program to treat an as a string type at all. Strongly typed definition language is a type-safe language.

2) weakly typed definition language:

A language in which data types can be ignored. In contrast to strongly typed definition languages, a variable can assign values of different data types.

Strongly typed languages may be slightly slower than weakly typed languages in speed, but the rigor brought by strongly typed languages can effectively avoid many errors. In addition, there is no connection between "whether the language is dynamic" and "whether the language is type-safe"!

For example, Python is a dynamic language, a strongly typed language (a type-safe language), VBScript is a dynamic language, a weakly typed language (a type-unsafe language), and JAVA is a static language, a strongly typed language (a type-safe language).

For explanations of various language types, please refer to: http://blog.csdn.net/aiming66/article/details/78570784#t3

With this in mind, let's talk about why JavaScript is a weakly typed language. After thinking about it, I think it can be explained by a piece of code. Maybe it's more straightforward.

Js exercises var num=0; alert (typeof num); num= "123"; alert (typeof num); num=true; alert (typeof num); num= new Date (); alert (typeof num)

Among them, let me explain the following code. The following few lines of code are shown in the following figure, we can not see that at the beginning, we only created a variable num, for the var type, but we can assign it various types: numeric type, string, Boolean type, object type, so we can infer that JavaScript is a weakly typed language.

A variable in javascript can be assigned values of different data types, which allows implicit conversions of variable types, mandatory type conversions, etc., such as strings and values that can be converted automatically, while strongly typed languages generally do not allow this.

Var num=0;alert (typeof num)

Num= "123"; alert (typeof num)

Num=true;alert (typeof num)

Num= new Date (); alert (typeof num)

At this point, the study on "what type of javascript is" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report