search
HomeWeb Front-endJS TutorialJavaScript 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.
Statement
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
JavaScript in Action: Real-World Examples and ProjectsJavaScript in Action: Real-World Examples and ProjectsApr 19, 2025 am 12:13 AM

JavaScript's application in the real world includes front-end and back-end development. 1) Display front-end applications by building a TODO list application, involving DOM operations and event processing. 2) Build RESTfulAPI through Node.js and Express to demonstrate back-end applications.

JavaScript and the Web: Core Functionality and Use CasesJavaScript and the Web: Core Functionality and Use CasesApr 18, 2025 am 12:19 AM

The main uses of JavaScript in web development include client interaction, form verification and asynchronous communication. 1) Dynamic content update and user interaction through DOM operations; 2) Client verification is carried out before the user submits data to improve the user experience; 3) Refreshless communication with the server is achieved through AJAX technology.

Understanding the JavaScript Engine: Implementation DetailsUnderstanding the JavaScript Engine: Implementation DetailsApr 17, 2025 am 12:05 AM

Understanding how JavaScript engine works internally is important to developers because it helps write more efficient code and understand performance bottlenecks and optimization strategies. 1) The engine's workflow includes three stages: parsing, compiling and execution; 2) During the execution process, the engine will perform dynamic optimization, such as inline cache and hidden classes; 3) Best practices include avoiding global variables, optimizing loops, using const and lets, and avoiding excessive use of closures.

Python vs. JavaScript: The Learning Curve and Ease of UsePython vs. JavaScript: The Learning Curve and Ease of UseApr 16, 2025 am 12:12 AM

Python is more suitable for beginners, with a smooth learning curve and concise syntax; JavaScript is suitable for front-end development, with a steep learning curve and flexible syntax. 1. Python syntax is intuitive and suitable for data science and back-end development. 2. JavaScript is flexible and widely used in front-end and server-side programming.

Python vs. JavaScript: Community, Libraries, and ResourcesPython vs. JavaScript: Community, Libraries, and ResourcesApr 15, 2025 am 12:16 AM

Python and JavaScript have their own advantages and disadvantages in terms of community, libraries and resources. 1) The Python community is friendly and suitable for beginners, but the front-end development resources are not as rich as JavaScript. 2) Python is powerful in data science and machine learning libraries, while JavaScript is better in front-end development libraries and frameworks. 3) Both have rich learning resources, but Python is suitable for starting with official documents, while JavaScript is better with MDNWebDocs. The choice should be based on project needs and personal interests.

From C/C   to JavaScript: How It All WorksFrom C/C to JavaScript: How It All WorksApr 14, 2025 am 12:05 AM

The shift from C/C to JavaScript requires adapting to dynamic typing, garbage collection and asynchronous programming. 1) C/C is a statically typed language that requires manual memory management, while JavaScript is dynamically typed and garbage collection is automatically processed. 2) C/C needs to be compiled into machine code, while JavaScript is an interpreted language. 3) JavaScript introduces concepts such as closures, prototype chains and Promise, which enhances flexibility and asynchronous programming capabilities.

JavaScript Engines: Comparing ImplementationsJavaScript Engines: Comparing ImplementationsApr 13, 2025 am 12:05 AM

Different JavaScript engines have different effects when parsing and executing JavaScript code, because the implementation principles and optimization strategies of each engine differ. 1. Lexical analysis: convert source code into lexical unit. 2. Grammar analysis: Generate an abstract syntax tree. 3. Optimization and compilation: Generate machine code through the JIT compiler. 4. Execute: Run the machine code. V8 engine optimizes through instant compilation and hidden class, SpiderMonkey uses a type inference system, resulting in different performance performance on the same code.

Beyond the Browser: JavaScript in the Real WorldBeyond the Browser: JavaScript in the Real WorldApr 12, 2025 am 12:06 AM

JavaScript's applications in the real world include server-side programming, mobile application development and Internet of Things control: 1. Server-side programming is realized through Node.js, suitable for high concurrent request processing. 2. Mobile application development is carried out through ReactNative and supports cross-platform deployment. 3. Used for IoT device control through Johnny-Five library, suitable for hardware interaction.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Tools

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment