In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly explains the "what types of JS variables", the content of the explanation 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 "what types of JS variables" bar!
Basic types and reference types
In the previous section, we introduced the data types in JavaScript, in which the basic types, such as numbers and Boolean values, all have a fixed size in memory, and we access the basic types of data directly through variables. For reference types, such as objects, arrays, and functions, because their size is unlimited in principle, we access them through access to their references, which is an address that points to the location where complex objects are actually stored.
The difference between a basic type and a reference type is obvious. Let's look at a few examples:
Var xpend1umbram / number x, basic type
Var yawxpole / numeral y, basic type
Print (x)
Print (y)
Xchang2 / modify the value of x
The value of print (x); / / x changes to 2
The value of print (y) / / y will not change.
The running results are as follows:
The result of such a run should be unexpected, and there is nothing special about it. Let's take a look at the example of reference type. Because the length of the array is not fixed, it can be dynamically added or deleted, so the array is a reference type:
Var array= [1,2,3,4,5]
Var arrayRef=array
Array.push (6)
Print (arrayRef)
The reference points to the address, that is, the reference does not point to the reference itself, but to the actual object that the reference corresponds to. So by modifying the array pointed to by array, arrayRef points to the same object, so the effect is as follows:
1,2,3,4,5,6
Scope of variables
The area in which the variable is defined is its scope, and the global variable has a global scope; local variables, such as those declared inside the function, have local scope and cannot be directly accessed outside the function. For example:
What is the meaning of JS variable
Var variable= "out"
Function func () {
Var variable= "in"
Print (variable); / / print "in"
}
Func ()
Print (variable); / / print "out"
It should be noted that the var keyword is required within the function, and if variables are used without writing the var keyword, the default operation is for global objects, such as:
Var variable= "out"
Function func () {
Variable= "in"; / / Note that there is no var keyword before this variable.
Print (variable)
}
Func ()
Print (variable); / / the global variable variable has been modified
Because variable is used in the function func without the keyword var, the default is the action on the global object variable property (changing the value of variable to in), so this code prints:
In
In
Thank you for your reading, the above is the content of "what types of JS variables", after the study of this article, I believe you have a deeper understanding of what types of JS variables have, and the specific use 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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.