Javascript variable naming convention scope of Variables

Source: Internet
Author: User

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:

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.