The basic syntax of JavaScript __java

Source: Internet
Author: User
Tags case statement constant

Http://blog.sina.com.cn/s/blog_6e44dfbf0100noal.html

The basic syntax of JavaScript

JavaScript languages, like other languages, have their own basic data types, expressions and operators, and basic program frameworks.

I. Basic data types

There are four basic types of data in JavaScript

Numeric: integers and real numbers

String: Characters or values enclosed by "" or ""

Logical type: With True or false

Null value: Means nothing

The data in the basic data type of JavaScript can be a constant or a variable. Because JavaScript takes the form of a weak type, a variable or constant of one data does not have to be declared first, but rather the type of its data when using or assigning a value. Of course, you can declare the type of the data first by automatically stating its data type when you assign a value.

Second, the control structure and cycle in JavaScript

1, if statement, If......else statement

2, Switch....case statement

3, for Loop statement

4, break, continue statement

5, label statements and with statements

This is mainly about the label statement and the WITH statement, and several other statement types are the same as C #.

Label statement:

With the advent of the JavaScript 1.2 version, the language provides a more efficient way to use continue and break statements, where label statements can be placed before any control structure that can nest other statements. It lets you jump out of conditional statements and loop statements and go to other places in your program. You can see the use of the statement in the following program.

<title> JavaScript unleashed</title>

<body>

<script language= "Javascript 1.2" type= "Text/javascript" >

<!--

Variable declaration

var stopx=4;

var stopy=9;

document.write ("All in (0,0) and (");

The x,y combination of Docunment.write (stopx+ "," +stopy+ ") has:<br>");

LOOPX:

for (Var x=0;x<10;++x) {

for (Var y=0;y<10;++y) {

document.write ("(" +x+ "," +y+ ")");

if ((X==STOPX) && (y==stopy)

{

Break loopx;

}

}

document.write ("<br>");

}

document.write ("x= after completion of the <br> cycle" +x);

document.write ("y= after the end of the <br> cycle" +y);

-->

</script>

</body>

In this case, the for loop is labeled with a user-defined LOOPX label, which can jump or continue for the for loop, regardless of how the program is nested. If there are no label statements, the break statement terminates only the loop that produces the Y-value.

With statement:

With the WITH statement, you do not have to repeat the specified Reference object when accessing object properties and methods. In a With statement block, properties and methods that are not recognized by JavaScript are related to the object specified by the statement. The syntax format for the WITH statement is as follows:

With (object) {

Statements

}

Object indicates the Reference object when the object defaults in the statement group. Here we use the more familiar document object to give examples of the WITH statement.

For example, when you use the write () or Writeln () method associated with a Document object, you often use the following form:
Document.writeln (hello!)

If you need to display a large amount of data, you will use the same Document.writeln statement multiple times. At this point, you can reduce the amount of the statement by placing all statements with the Document object as the reference object in the With statement block, as in the following procedure. The following is an example of the use of a with statement:

<title>javascript unleashed</title>

<body>

<script type= "Text/javascript" >

<!--

With (document) {

Write ("Hello");

Write ("<br> the title of this document is: \" "+title+" \ ".");

Write ("<br> the URL of this document is:" +url);

Write ("<br>" Now you don't have to write the document object prefix every time);

}

-->

</script>

</body>

This allows you to remove the document prefix when you use the methods and properties of the document. The title and URL in the program are the properties of the Document object. In general, Document.title and Document.url should be written.


Http://www.cnblogs.com/BeginMan/p/3435187.html

JS Overview

Here
The great God level talk about JavaScript programming style grammatical structure

1. Character Set: Unicode (superset of ASCII and Latin-1)
2. Case sensitive
3. Note://////////////* */
4. Direct: Data values directly used in the program, such as 1, ' AB ', true,/ad/,null, etc.
5. Identifiers and reserved words
6. Optional semicolon: If the statement is syntactically correct and has an exclusive line, you can omit the semicolon that follows. types, values, and variables Type:

The data types of JavaScript are grouped into two categories: original Type and Object type
Original type: Number, String, Boolean value;

JavaScript has two special original values: null (empty), undefined (undefined)

Object type: Handles numbers, strings, booleans, NULL, and undefined objects, objects are collections of attributes, and each property is made up of "name/value pairs" (values can be values of the original type, or objects). There is a special object that is the global object.

Arrays: Normal JavaScript objects are unordered collections, and JavaScript also defines a special object-array that represents an ordered set with indexes.
Function: JS also defines another special object-a function, which is an object that has executable code associated with it.
Class: If a function is used to initialize (using the new operator) a new object that we call a constructor, each constructor defines a class of objects-a collection of objects initialized by the constructor. A class can be considered as a subtype of an object type, with the following classes: Array class, function class, date class, Regular (RegExp) class, Exception (Error) class. You can also customize the class.

Note: JS types can be divided into the original type and object type, can also be divided into the type of owning the method and can not have the type of method, also can be divided into variable types and immutable types. such as objects and arrays are mutable types, JS can change the object's property values and array elements of values, numbers, strings, Boolean values, null and undefined belong to the mutable type.
Intelligent type conversion: JS is free to convert data types, such as using a string where the number is used, will automatically convert the number to a string. Number:

Unlike other programming languages, JS does not differentiate between integer and floating-point values, and all of the JavaScript numbers are represented by floating points.
For numeric operations, refer to the Math object, string:

Note \ n is used to split rows.
About escape: In JS, the backslash (\) has a special purpose, the backslash symbol after adding a character, it will no longer represent their literal meaning. For example, \ n represents a newline character. \ ' represents single quotes (or apostrophes). such as: var str = ' you\ ' re right! ';
See String Method Boolean value for more information:

The value of any JS can be converted to a Boolean value, and the following value is converted to false:

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.