Javascript variable naming convention scope of Variables
When variables were small, we learned this application: X + 1 = 2; Q: What is X equal? The answer is 1 by the way. It's very clever. We call this X an unknown number or a variable is actually a container used to store data. But we never know what the result is. It can only store one value. Var variable name; 1. The variable name must start with a letter or subscript sign "_" or "$. 2. The variable name cannot contain more than 255 characters. 3. spaces are not allowed in variable names. 4. You do not need to use keywords and reserved symbols in the script language as variable names. 5. Variable names are case sensitive. (Javascript is a case-sensitive language) 6. Wide variable names are in Chinese. All browsers support this feature. However, if the variable name is added with Chinese Punctuation Marks, only ie is supported. Other Browsers Do Not. Try not to use Chinese characters. Var num1 = 0, num2 = 0; // declare multiple variables 1. Which of the following four variable declaration statements is named correctly? A. var for B. var txt_name C. var myname myval D. var 2 s answer: B A is the key sub-error. C has spaces or is wrong. D cannot start with A number. 2. which of the following statements defines a variable named Myval and assigns its value to 2205? A. var myval = 2205 B. var MyVal = 2205 C. var Myval = 2205 D. Myval = 2205 answer C 3. In Javascript, which of the following statements will definitely generate A running error? A. var _ variable = NaN; B, var 0bj = 123; C, var obj = "//"; D, var obj = ''; answer: Hey, this test is eye-catching. The answer is B because the variable cannot start with 0, although A has correct Chinese characters. Scope variable range of the variable: global variable local variable global variable: What is declared externally is that the global variable does not include the internal declaration of the local variable with var: