JavaScript basic knowledge points
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值是布尔值
For example: +-8*/
var num=24; var myresult1=++num%4+6*2;//myresult是多少呢? var myresult2=num%4+6*2;//myresult是多少呢?
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'];
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]; //fucation
var arr=[[1,2],[3,4]]; arr[0][1]; //2arr[1][1]; //4
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; //10001
var arr=['a','b','c']; arr.length; //3arr.length=2; arr; //['a','b']
var myarr=new Array(6); console.log(myarray);
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]);
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]);
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]);
Simple for loop:
var arr=['a','b','c']; for(var i=0; i<arr.length; i++){ console.log(arr[i]); }

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).

Introduction to the method of obtaining HTTP status code in JavaScript: In front-end development, we often need to deal with the interaction with the back-end interface, and HTTP status code is a very important part of it. Understanding and obtaining HTTP status codes helps us better handle the data returned by the interface. This article will introduce how to use JavaScript to obtain HTTP status codes and provide specific code examples. 1. What is HTTP status code? HTTP status code means that when the browser initiates a request to the server, the service
