JavaScript learning
Tag (space separated) variable
1. What is a variable
A variable is a container that stores book values;
2 .Game Rules
【Variable Naming】Variables can be composed of letters, numbers, underscores (_) or dollar signs ($).
1. Must start with a letter, underscore, or dollar sign, and can be followed by letters, underscores, dollar signs, and numbers.
2. Variable names are case-sensitive, such as: myvar and myVarhi are two different variables.
3. JavaScript keywords and reserved words are not allowed to be used as variable names, such as break and Boolean.
3. Variable declaration and assignment
var myvar=123;
4. Data type
string (string)
Nubmber (number)
Boolean (for example, true and false have only two types)
Array (array)
Object (object)
var mychar1="双引号包起来的字符串";//这是字符串 var mychar2='单引号包起来的字符串';//这也是字符串 var mychar3='小蒜:"我喜欢我们班的小可。"';//字符串中有双引号,用单引号包含 var mychar4="Uncle Wang:"\"小蒜啊,'学习好'才能吸引女孩哦~\""; //或者在特定符号(引号)前使用\符号,使其转义输出 var mynum1=6; //这是数字6var mynum2=6.00; //这也是数字6> var mynum3=123e;//这是使用科学(指数)计算法来书写的12300000 var mynum4=123e-5;//这是0.00123var mynum5=ture;//这是布尔值 var mynum6=[1,2,3];//这是数组 var myobject={"p":"Hello"};//这是对象
var y="you"; var mysay="I"+"love"+y; //=后面是串表达式,mysay值是字符串 var mynum=12+6*2;//=后面是数值表达式,mynum值是数值 var mynum>12;//=后面是布尔表达式,mysay值是布尔值2. Operation Symbol 2.1 Arithmetic operator
For example: +-8*/
var num=24; var myresult1=++num%4+6*2;//myresult是多少呢? var myresult2=num%4+6*2;//myresult是多少呢?2.2 Assignment operator It can be simplified by placing the arithmetic operator before =. For example, num%=4 is equivalent to num=num%4. 2.3 Comparison operators
For example:>,=,==equal to
===all equal to
! = is not equal to
&& (series connection)
|| (parallel connection)
= copy symbol.
If operations at the same level are performed from left to right, multi-level brackets are from inside to outside.
As a reminder, when you can't tell the priority, just add parentheses to remember the order of operations.
Exercise: Link numbers and strings
Indicate the following non-string result
One sentence understanding: Variables that can store multiple data
//表达形式一var arr=[]; var arr[0]='a'; var arr=[1]='b'; var arr=[2]='c'; var arr=[3]='d';//表达形式二 var arr=['a''b''c''d'];2. What can be installed?
Any type of data can be put into an array.
var arr=['x',{a:1},[1,2,3], fucation(){return true;}]; arr[0]; //stringarr[1]; //Objectarr[2]; //Arrayarr[3]; //fucationIt can be seen that the elements in the array can also be an array. We call this form a multi-dimensional array.
var arr=[[1,2],[3,4]]; arr[0][1]; //2arr[1][1]; //43.length attribute
3.1 The length attribute of the array can return the number of members of the array.
var arr=['a','b']; arr.length; //2arr[2]=;'c'; arr.length; //3arr[9]='d'; arr.length; //10arr[1000]='e'; arr.lengh; //10001It can be found that the numeric key values of the array do not need to be consecutive, and the value of the length attribute is always equal to the largest key value greater than 1. 3.2 The length attribute is writable. If you manually set a value for the current number of members in Xiaoyu, the members of the array will automatically be reduced to the length set by length.
var arr=['a','b','c']; arr.length; //3arr.length=2; arr; //['a','b']When the length attribute of the array is set to 2, that is, the largest integer can only be 1, so the element ('c') corresponding to the key value 2 is automatically deleted. Therefore, an effective way to clear an array is to set the length attribute of the array to 0. 3.3 The length of the arrayIt should be noted that because the index of the array always starts from 0, the upper and lower limits of an array are: 0 and length-1 respectively. If the length of the array is 5, the upper and lower limits of the array are doubled to 0 and 4. 4. Create an array
var myarr=new Array(6); console.log(myarray);5. Assign an array
var myarr=new Array(3); myarr[0]="小五"; myarr[1]="小明"; myarr[2]="月影"; console.log("班里学号为0的是:"+myarr[0]); console.log("班里学号为1的是:"+myarr[1]); console.log("班里学号为2的是:"+myarr[2]); var arr=["1","abc","myarr"]; console.log(arr[1]);6. Add a new element
myarr[0]="小五"; myarr[1]="小明"; myarr[2]="月影"; console.log("班里学号为0的是:"+myarr[0]); console.log("班里学号为1的是:"+myarr[1]); console.log("班里学号为2的是:"+myarr[2]); myarr[3]="小新"; console.log(myarr[3]); myarr[0]="小五"; myarr[1]="小明"; myarr[2]="月影"; console.log("班里学号为0的是:"+myarr[0]); console.log("班里学号为1的是:"+myarr[1]); console.log("班里学号为2的是:"+myarr[2]); myarr[3]="小新"; console.log(myarr[3]);7. Use an array literal
To get the value of an array element, just use the array variable and provide an index.
var myarr=["小雷","小可","小新","小明","月影"]; var mynum=4; console.log("学号为4的是"+myarr[mynum]);
var myarr=[[0,2,3],[1,2,3]] myarr[0][1]=5;//将5的值传入数组中,覆盖原有值。 console.log(myarr[0][1]);Knowledge point expansion
Simple for loop:
var arr=['a','b','c']; for(var i=0; i<arr.length; i++){ console.log(arr[i]); }The above is JavaScript Basic knowledge points, please pay attention to the PHP Chinese website (www.php.cn) for more related content!

JavaScript can be used for front-end and back-end development. The front-end enhances the user experience through DOM operations, and the back-end handles server tasks through Node.js. 1. Front-end example: Change the content of the web page text. 2. Backend example: Create a Node.js server.

Choosing Python or JavaScript should be based on career development, learning curve and ecosystem: 1) Career development: Python is suitable for data science and back-end development, while JavaScript is suitable for front-end and full-stack development. 2) Learning curve: Python syntax is concise and suitable for beginners; JavaScript syntax is flexible. 3) Ecosystem: Python has rich scientific computing libraries, and JavaScript has a powerful front-end framework.

The power of the JavaScript framework lies in simplifying development, improving user experience and application performance. When choosing a framework, consider: 1. Project size and complexity, 2. Team experience, 3. Ecosystem and community support.

Introduction I know you may find it strange, what exactly does JavaScript, C and browser have to do? They seem to be unrelated, but in fact, they play a very important role in modern web development. Today we will discuss the close connection between these three. Through this article, you will learn how JavaScript runs in the browser, the role of C in the browser engine, and how they work together to drive rendering and interaction of web pages. We all know the relationship between JavaScript and browser. JavaScript is the core language of front-end development. It runs directly in the browser, making web pages vivid and interesting. Have you ever wondered why JavaScr

Node.js excels at efficient I/O, largely thanks to streams. Streams process data incrementally, avoiding memory overload—ideal for large files, network tasks, and real-time applications. Combining streams with TypeScript's type safety creates a powe

The differences in performance and efficiency between Python and JavaScript are mainly reflected in: 1) As an interpreted language, Python runs slowly but has high development efficiency and is suitable for rapid prototype development; 2) JavaScript is limited to single thread in the browser, but multi-threading and asynchronous I/O can be used to improve performance in Node.js, and both have advantages in actual projects.

JavaScript originated in 1995 and was created by Brandon Ike, and realized the language into C. 1.C language provides high performance and system-level programming capabilities for JavaScript. 2. JavaScript's memory management and performance optimization rely on C language. 3. The cross-platform feature of C language helps JavaScript run efficiently on different operating systems.

JavaScript runs in browsers and Node.js environments and relies on the JavaScript engine to parse and execute code. 1) Generate abstract syntax tree (AST) in the parsing stage; 2) convert AST into bytecode or machine code in the compilation stage; 3) execute the compiled code in the execution stage.


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

SublimeText3 Linux new version
SublimeText3 Linux latest version

Dreamweaver CS6
Visual web development tools

Dreamweaver Mac version
Visual web development tools

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft
