JavaScript variables
Variables in JavaScript have similar meanings to variables in many programming languages. You can imagine variables as an empty box that can be used to hold things. Variable declarations in JavaScript have certain rules. The first letter of a variable must be an English letter. , Can be followed by underscore "_" or numbers, such as A_01, BBB, C02... etc. Note that when declaring variables, the case must be set first, because JavaScript variables are case-sensitive, such as A_01 It is a different variable from a_01! In addition, the use of Chinese is not currently supported.
JavaScript variable declaration example
var a;
a='10';
var b='20';
c='30';
--></script>
JavaScript can declare a variable in two ways. In the example, a variable a is declared through var. The second line a='10' means that the variable value is set to the integer 10. We can also use the equal sign to give the variable value in the declaration place. Like var b='20' in the third line, a more simplified way of writing is to look at c='30' in the fourth line, which means you don't even need to declare. There is no special restriction on the length of variable names, but too long values should not be used to avoid unmanageable when there are more and more codes.
Types of JavaScript variables
JavaScript will automatically process the types of variables. After declaring a variable and assigning a value, JavaScript will judge by itself.
var abc;
abc=100; // Integer type
abc="Test Text"; // String type
abc=true; // Boolean value type
abc=new Array() // Array type
--></script>
JavaScript Global Variables and Local Variables
var A01='100'; //Global Variables
function Test(){
var A02='200'; //Local Variables
}
--></script>
Post a Comment
0 Comments