Home > Web Front-end > JS Tutorial > JavaScript basic syntax analysis instructions_basic knowledge

JavaScript basic syntax analysis instructions_basic knowledge

WBOY
Release: 2016-05-16 19:03:42
Original
877 people have browsed it

I taught css and javascript a few days ago in phpchina to learn PCTI. Let me show you first
Identifiers of javascript

Identifiers refer to symbols defined in javascript, such as variable names, function names, arrays name and so on.
Identifiers can be composed of uppercase and lowercase letters, numbers, underscores, and dollar signs in any order. Identifiers cannot start with numbers, and they cannot use reserved keywords in JavaScript.
javasceipt is strictly case-sensitive. Each function ends with a semicolon after execution. Each word is separated by spaces, tabs, newlines, or delimiters such as braces and parentheses.
~~~~~~~~Although the above part is a bit nagging, it needs to be strictly followed, so I still have to write it~~~~~~~~~~~~~~~~

Basic data types and constants

Integer constants

Hexadecimal starts with 0x or 0X, such as 0x8a.
Octal must start with 0, for example: 0123.
The first digit of the decimal number cannot 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
I won’t say much about the above part. You don’t need to go into details but you must have a concept.
Boolean value Boolean
true and false. true is true and false is false

null constant null empty, keyword It indicates that the keyword contained in the variable is invalid, in other words, the variable is not saved 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, the property is a member of the Global object, which is available after the script engine is initialized. If a variable has been declared but not initialized, its value is undefined.

String constant
"this is JavaScript ppt", 'abc', "a", "".
Special characters in the string need to be represented by a backslash () followed by an ordinary character, such as: r, , t, b, ', ", \ .
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Variable
in javascript To declare a variable in, you need to declare it with the var keyword, and assign a value to it when declaring the variable.

For example: var name="zhansan";
Give another type of data to the assignment
For example: var name=123;
Use it directly without prior declaration
For example: x=1234;
~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~
Operators
Operators include: arithmetic operators, assignment operators, comparison operators, logical operators, bitwise operators
I won’t write more about the others. Just write down the logical operators and bitwise operators in JavaScript.
Logical operator
&& Logical AND, returns true when the left and right operands are true, otherwise returns false.
|| Logical Or, return false when the left and right operands are false, otherwise return true.
!= Logical negation, return false when the operand is true, otherwise return true.
Bitwise operator
bit Operations are used to operate on each binary bit in the operand, including bit logic operators and bit shift operators.
& Only if both two bits participating in the operation are 1, the result of the operation will be 1, otherwise it will be 0.
| Only if the two bits participating in the operation are both 0, the result of the operation will be 0, otherwise it will be 1.
^ Only if the two bits participating in the operation are different, the result of the operation will be 1, otherwise it will be 0.
>> Move the binary data of the left operand in the memory to the right by the number of digits specified by the right operand, shift the empty part to the left, and fill in the original highest binary value of the left operand
>>> Shift the binary data of the left operand in the memory to the right by the number of digits specified by the right operand.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Program flow control
Sequential structure, if condition selection statement, switch selection statement, while loop statement, do while statement, for loop statement, and break and continue statements.
First let’s talk about the if conditional selection statement
if (conditional statement) Use if to judge
{
Execute statement block 1; If it is true (true), execute statement 1
}
else
{
Execute statement 2; If it is false, execute statement 2
}

Abbreviation of if
{
Add more: if(x == null ) or if(typeof(x) == "undefined") can be abbreviated as if(!x).
Add more: Variable = Boolean expression? Statement 1: Statement 2;
For example: y = x >0 ? ; First set a variable x=2
Switch(x) Then switch determines
{
case 1: case value Set the value of switch
alert(“monday”) ; Alert statement block When switch selects the value, the value of alert is executed
break; break jumps out: jump out of the program after execution
case 2:
alert("Tuesday"); Browser Pop-up message
break;
case 3:
alert(“wendnesday”);
break;
default: Default: If none of the above conditions are met, run this code
              alert(“sorry, I don’t know”);
}
Then the result of executing the above statement is “tuesday”

switch can also be used like this
var x = 2 ;
switch(x)
{
Case 1:
Case 2:
Case 3:
Case 4:
Case 5:
alert(“working day ”);
break;
Default:
alert(“off day”);
}
Try it yourself and see what the effect is.

while loop statement
This is a simple example of a while loop statement
var x = 1; First we set a variable x=1
while(x {
alert("x = " x) is the value of x added after outputting it as it is
It’s execution first and judgment later.
for loop statement
The following is an example of a for loop
var output = “”; First set a variable but do not assign a value
for(var x= 1; x {
output = output “ x = ” x; The variable output is equal to utput plus the original output “x=" plus the value of x
}
alert (output); The browser pops up the value of the variable output

Break and continue statements
break is to jump out of the current program
continue is to stop the current iteration of the loop and start a new iteration.
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template