JavaScript Basic Grammar Analysis Description _ Basics

Source: Internet
Author: User
Tags arithmetic operators bitwise bitwise operators constant logical operators switch loop

Phpchina learned pcti a few days ago to teach CSS and JavaScript first to see
The identifier for JavaScript

Identifiers are symbols defined in JavaScript such as variable names, function names, array names, and so on.
Identifiers can consist of any sequence of uppercase and lowercase letters, numbers, underscores, and dollar signs, identifiers cannot start with numbers, and cannot use reserved keywords in javascript.
Javasceipt is strictly case-sensitive, each function is executed with a semicolon, separated by a delimiter such as a space, tab, line break, or curly brace.
~~~~~~~~ the above part although some nagging, but need to strictly abide by, so still want to write on ~~~~~~~~~~~~~~~~

Types and constants of basic data

Integral type Constants

Hexadecimal begins with a 0x or 0X, such as 0x8a.
Octal must start with 0, for example: 0123.
The first digit in the decimal can not be 0 (except the number 0), for example: 123.
Real constants

12.32, 192.98, 5E7, 4e5, etc.
.0001, 0.0001, 1e-4, 1.0e-4
The above section I do not say more, do not need to delve into but must have the concept.
Boolean value Boolean
True and False. True to true false to False

NULL constant NULL, as a keyword it indicates that the variable contains a keyword that is invalid, in other words, the variable does not hold a valid number, String, Boolean, array, or object. You can clear the contents of a variable by assigning a null value to it.

Undefined constant undefined undefined, property is a member of the Global object that is available after the script engine initializes. If a variable has been declared but has not been initialized, then the value of the variable is undefined.

string-Type Constants
"This is JavaScript ppt", "abc", "A", "" ".
A special character in a string that needs to be represented by a backslash (\) followed by a normal character, for example: \ r, \ n, \ t, \b, \, \, \ \.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Variable
Declaring a variable in JavaScript needs to be declared with the Var keyword, and the variable will be assigned a value when it is declared.

Columns such as: Var name= "Zhansan";
Give a different type of data to the assignment.
For example: Var name=123;
Direct use without prior declaration
For example: x=1234;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Operator
Operators include: arithmetic operators, assignment operators, comparison operators, logical operators, bitwise operators.
I'm not going to write anything else. I just write down the logical and bitwise operators in JavaScript.
logical operators
&& logic to return True when both the left and right operands are true, or false.
|| Logic or, returns False when the operands on both sides are false, otherwise true.
!= logic is not, returns False when the operand is true, otherwise true.
Bitwise operators
Bitwise operations are used to perform operations on each bits in the operand, including the bit logical operators and the displacement operators.
& Only two bits in the operation are 1, the result of the operation is 1, otherwise 0.
| Only two bits of the participating operation are 0, the result of the operation is 0, otherwise 1.
^ Only the two-bit difference in the operation, the result of the operation is 1, otherwise 0.
>> shifts the left-hand operand to the right of the binary data in memory, the number of digits specified by the left-hand operand, and the left-empty portion of the left to fill the bits value of the original highest bit of the left-hand operand.
<< the left operand in memory binary data left to the right operand specified number of digits, the right to move empty part of 0.
>>> move the left-hand operand to the right of the binary data in memory to the right of the operand specified, and the left-empty part is 0.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Process Control of the program
Sequential structure, if condition selection statement, switch selection statement, while Loop statement, do While statement, for Loop statement, and break and continue statement.
First say if condition SELECT statement
if (conditional statement) using if to judge
{
EXECUTE statement block 1; If True (TRUE) executes the 1 statement
}
Else
{
EXECUTE statement 2; If False (False) executes the 2 statement
}

Shorthand for IF
{
Add: if (x = = null) or if (typeof (x) = "undefined") can be abbreviated to if (!X).
Add: variable = Boolean expression? Statement 1: Statement 2;
For example: y = x >0? x:-X;
}
An If statement can be nested in use.


Switch statement
The following is an example of a switch statement
Var x = 2; Set a variable first x=2
Switch (x) then switch to judge
{
Case 1:case Value set switch takes a few
Alert ("Monday"); Alert statement block executes the value of alert when the switch selects the value taken
Break Break jump: Jump out of the program after execution
Case 2:
Alert ("Tuesday"); Alert for browser pop-up information
Break
Case 3:
Alert ("Wendnesday");
Break
Default:default (default): Run this code if none of the above conditions match
Alert ("Sorry, I don ' t know");
}
Then the execution of the previous statement results in "Tuesday"

Switch can also be used in this way
var x = 2;
Switch (x)
{
Case 1:
Case 2:
Case 3:
Case 4:
Case 5:
Alert ("Working day");
Break
Default:
Alert ("Off Day");
}
Try to see for yourself what effect it is.

While Loop statement
This is a simple example of a while loop statement
var x = 1; First, we still set a variable x=1
while (x <3) then use a while to determine if X is less than 3
{
Alert ("x =" +x); If you judge X to be less than three then execute this paragraph, alert for browser pop-up information ("x=") is output (+x) as-is output after the value of X
x + +; and then x + + it means that if it's less than 3, it's cumulative
}
The difference between a do switch loop statement and a switch is that the switch is first judged and then executed, and the do switch is executed first and then judged.
For Loop statement
The following is an example of a For loop
var output = ""; Set a variable first but not assign a value
For (Var x= 1 <10; x + +) for determining whether the variable x=1 is less than 10 if less than 10 so X + +
{
Output = output + "x =" + x; Variable output equals Utput plus the value of "x=" plus X
}
alert (output); Browser popup variable output value

Break and Continue statements
Break to jump out of the current program
Continue is the current iteration of the Stop loop and begins a new iteration.
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.