In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-20 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains the "JavaScript variables can save a variety of data types", the article explains the content is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in-depth, together to study and learn "JavaScript variables can save multiple data types" bar!
JavaScript variables can hold multiple data types: numeric values, string values, arrays, objects, and so on:
Var length = 7; / / number
Var lastName = "Gates"; / / string
Var cars = ["Porsche", "Volvo", "BMW"]; / / Array
Var x = {firstName: "Bill", lastName: "Gates"}; / / object
The concept of data types
In the process of programming, data type is an important concept.
In order to be able to manipulate variables, it is important to understand the data type.
Without a data type, the computer cannot safely solve the problem:
Var x = 911 + "Porsche"
Does it make sense to add 911 to "Volvo"? Will this make a mistake or will it produce a result?
JavaScript will handle the above example like this:
Var x = "911" + "Porsche"
When a numeric value is added to a string, JavaScript treats the numeric value as a string.
Example
Var x = 911 + "Porsche"
Example
Var x = "Porsche" + 911
JavaScript evaluates the expression from left to right. Different orders produce different results:
JavaScript:
Var x = 911 + 7 + "Porsche"
Results:
918Porsche
JavaScript:
Var x = "Porsche" + 911 + 7
Results:
Porsche9117
In the first example, JavaScript treats 911 and 7 as numeric values until he meets "Porsche".
In the second example, because the first Operand is a string, all operands are treated as strings.
Thank you for your reading, the above is the content of "JavaScript variables can save multiple data types", after the study of this article, I believe you can save multiple data types of JavaScript variables have a deeper understanding of this problem, the specific use of the situation also needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.