JavaScript basic syntax analysis instructions_basic knowledge
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.

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



How to use WebSocket and JavaScript to implement an online speech recognition system Introduction: With the continuous development of technology, speech recognition technology has become an important part of the field of artificial intelligence. The online speech recognition system based on WebSocket and JavaScript has the characteristics of low latency, real-time and cross-platform, and has become a widely used solution. This article will introduce how to use WebSocket and JavaScript to implement an online speech recognition system.

WebSocket and JavaScript: Key technologies for realizing real-time monitoring systems Introduction: With the rapid development of Internet technology, real-time monitoring systems have been widely used in various fields. One of the key technologies to achieve real-time monitoring is the combination of WebSocket and JavaScript. This article will introduce the application of WebSocket and JavaScript in real-time monitoring systems, give code examples, and explain their implementation principles in detail. 1. WebSocket technology

Introduction to how to use JavaScript and WebSocket to implement a real-time online ordering system: With the popularity of the Internet and the advancement of technology, more and more restaurants have begun to provide online ordering services. In order to implement a real-time online ordering system, we can use JavaScript and WebSocket technology. WebSocket is a full-duplex communication protocol based on the TCP protocol, which can realize real-time two-way communication between the client and the server. In the real-time online ordering system, when the user selects dishes and places an order

How to use WebSocket and JavaScript to implement an online reservation system. In today's digital era, more and more businesses and services need to provide online reservation functions. It is crucial to implement an efficient and real-time online reservation system. This article will introduce how to use WebSocket and JavaScript to implement an online reservation system, and provide specific code examples. 1. What is WebSocket? WebSocket is a full-duplex method on a single TCP connection.

JavaScript and WebSocket: Building an efficient real-time weather forecast system Introduction: Today, the accuracy of weather forecasts is of great significance to daily life and decision-making. As technology develops, we can provide more accurate and reliable weather forecasts by obtaining weather data in real time. In this article, we will learn how to use JavaScript and WebSocket technology to build an efficient real-time weather forecast system. This article will demonstrate the implementation process through specific code examples. We

JavaScript tutorial: How to get HTTP status code, specific code examples are required. Preface: In web development, data interaction with the server is often involved. When communicating with the server, we often need to obtain the returned HTTP status code to determine whether the operation is successful, and perform corresponding processing based on different status codes. This article will teach you how to use JavaScript to obtain HTTP status codes and provide some practical code examples. Using XMLHttpRequest

Usage: In JavaScript, the insertBefore() method is used to insert a new node in the DOM tree. This method requires two parameters: the new node to be inserted and the reference node (that is, the node where the new node will be inserted).

JavaScript is a programming language widely used in web development, while WebSocket is a network protocol used for real-time communication. Combining the powerful functions of the two, we can create an efficient real-time image processing system. This article will introduce how to implement this system using JavaScript and WebSocket, and provide specific code examples. First, we need to clarify the requirements and goals of the real-time image processing system. Suppose we have a camera device that can collect real-time image data
