JavaScript Introductory Tutorial Three language basics "1"

Source: Internet
Author: User
Tags uppercase letter

First, the basic introduction

1, JavaScript is a case-sensitive language. (Var hello and var hello are different variables)

2. A marker in JavaScript refers to the name of a variable, function, attribute, or parameter of a function. Its naming rules are: The first character must be an English letter, an underscore, or a $ symbol. The next character can be an English letter, an underscore, or a $ symbol or a number (more numbers). The recommendations are all defined in English and are traditionally used in camel case format, i.e. the first letter is lowercase, leaving the first letter of each word capitalized. (For example: Myfirstscript)

3. JavaScript supports two types of annotations: the//Type and/* .... */type.

4, the statements in JavaScript end with a semicolon, of course, do not write semicolons will not go wrong, but from the compression, easy to read and performance perspective plus the best.

5. The combination of multiple statements is suggested to be placed in a {}, and in the control statement, even if a statement, plus {} makes the code clearer and easier to read.

if (i > 0)

{return true;}

6, there are some keywords in javascript can not be used as a marker. Given that there are too many keywords and the keywords are lowercase, you can include an uppercase letter when defining the marker. (For example: typeof is a keyword, but typeof can be used as a marker)

Second, the variable

 1, JavaScript variables are loosely typed, that is, you can save any type of data. The var operator is used when defining a variable, followed by a variable name, for example:

VAR message; (only declared, uninitialized variables, save a special value undefined)

var message1 = "Hello word!"; (Declare and initialize the variable, save a String value "Hello word!")

But Messge1 is not marked as a string type, and initialization simply assigns a value to the variable. We can also proceed as follows:

Message1 = 5;

Such operations are fully available in javascirpt and do not report errors. But it is not recommended to do so.

2. The JavaScript variable is divided into local variables and all variables according to the different scopes.

Variables defined within a function by the var operator are local variables in the body of the current function. However, variables that are not defined by the var operator are equivalent to global variables. For example:

var message = "message";

function Test () {

var message1 = "Message1";

Message2 = "Message2"; (not recommended)

alert (message); Legal

alert (MESSAGE1); Legal

alert (MESSAGE2); Legal

}

alert (message); Legal

alert (MESSAGE1); Not legal

alert (MESSAGE2); Legal

We can see that message2 can be referenced outside the function, but we do not recommend it because it is difficult to maintain and is prone to other unnecessary confusion.

Third, data variables

  1, there are five kinds of basic data types in Javascipt: Undefined, Null, Boolean, number, String. A complex type: Object.

2. Because JavaScript variables are loosely typed, a method is required to detect the type of value stored by the current variable: typeof. Using the typeof operator on a variable may return the following six types of strings:

Undefined this variable is undefined

Boolean This variable stores a Boolean value

String, which is a variable that stores strings

Number this variable stores a numeric value.

Object this variable stores objects or null

function is a variable that stores functions.

      

JavaScript Introductory Tutorial Three language basics "1"

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.