What language is JavaScript based on?
Javascript is an object-based language that can not only create objects, but also use existing objects. The object-based definition of the JavaScript standard: The infrastructure of the language and host is provided by objects, and a JavaScript program is a collection of objects that communicate with each other.
The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.
1. Introduction to javascript:
*Javascript is an object- and event-driven language, mainly used on the client.
– Object-based:
Many objects are provided and can be used directly.
--Event-driven:
The web page made by html has a static effect, and the web page made by javascript has a dynamic effect.
--Client:
Mainly refers to the browser.
*Characteristics of js:
(1) Interactivity:
--Dynamic interaction of information.
(2) Security:
--s cannot access files in the local disk.
(3) Cross-platform:
--Unlike java, js directly uses browser cross-platform.
*The difference between javascript and java: (no connection)
1)java is released by sun company (now oracle)
Released by Jing Company.
2) JavaScript is object-based, and java is object-oriented
3) Java is a strongly typed language, and js is a weakly typed language.
4) js can be executed after parsing, while java needs to be compiled first and then executed.
*The composition of js
has three parts
(1) ECMAScript
--ECMA: European Computer Association, which specifies the syntax for js.
(2) BOM
--browser object model: Browser object model.
(3) DOM
--document object model: Document object model.
2. How to combine js and html (two ways)
The first one:
--Use a tag:
<`script type="text/javascript" > js代码 </script>`
Second type:
--Introducing external files:
-Create a .js file.
-- <script type="text/javascript" src=" 外部文件地址 "> </script>
Note: Do not write other js code in the second script tag, as it will not be executed.
3. Primitive types and declared variables of js
//js中,只有五个原始类型: //string: 字符串 var str = “abc”; //number: 数字类型 var num = 123; //boolean: true和false var falg = true; //null: *** 获取对象的引用,null用来表示引用为空,所有对象的引用都为 object var date = new Date(); //undifined //定义一个变量,没有被赋值 var aa; typeof() ; //查看当前变量的数据类型。 alert() ; //在页面跳出一个对话框。 document.write();//直接想页面输出的语句(可以把括号内的语句输出到页面上) 也可以输出html代码。
4. Statements of js
–also found in js These statements
if judgment statement
=: ==: � � by by by
--switch(a){ case 1: break; case 2: break; default: … … }
5. js operators
The addition and addition of strings in js Subtraction operation var str = “123”;
***When adding, what is done is the concatenation of strings. ***When subtracting, what is done is subtraction operation.
如: alert(str+1)//结果为1231. alert(str-1)//结果为122.
Note: When str is not a number, the subtraction operation will prompt an error.
var str = “abc”; alert(str-1);//结果为:提示NaN: 表示这不是一个数字。
**boolean can also perform mathematical operations
If set to true, when performing mathematical operations, the equivalent value is: 1
The difference between == and ===
They are both used to make equality judgments,// == 比较的是 值 // === 比较的是 值 和 类型 如: var i = “5”; i5 // true i=5 // false。
Six, js array
//–js数组定义方式(三种): //第一种: var arr = [1,2,3] || var arr = [1,“2”,true] //第二种: 使用内置对象 Array, var arr = new Array(5); //定义了一个长度为5的数组。 arr[0] = “1”; arr[1] = 2; arr[2] = true; //第三种: 使用内置对象 Araay, var arr = new Array(3,“4”,true);//定义一个数组,其中值为:3,4,true
–The length of the array is variable.
–Arrays can store different types of values7. Methods in js
There are three ways to define methods in js: //第一种方式:
//使用一个关键字 function
function 方法名(参数列表){
方法体;
返回值(视需求,可有可无);
}
for example:
function add(a ,b,c){
var sum = a+b+c;
return sum;
}
(调用方法名,使用定义的方法)
//第二种方式:
//匿名方法。
*** var 变量名 = function(参数列表){
方法体;
返回值;
}
//如:
var add = funtion(a,b){
var sum = a+b;
return sum;
}
//(之后使用变量名调用方法)
//**第三种方式:
//动态方法。
//使用一个js的内置对象 Function
var 变量名 = new Function(“参数列表”,“方法体 和 返回值”); (注意,参数和方法体之间是逗号)
var add = new Function(“a,b”, “var sum=a+b; return sum”);
(之后使用变量名调用函数)
//注意,此方式中,可以预先定义好参数列表,和方法体与方法名,在定义方法的时候直接传进来。
Copy after login8. Global variables of js, and local variables
//第一种方式: //使用一个关键字 function function 方法名(参数列表){ 方法体; 返回值(视需求,可有可无); } for example: function add(a ,b,c){ var sum = a+b+c; return sum; } (调用方法名,使用定义的方法) //第二种方式: //匿名方法。 *** var 变量名 = function(参数列表){ 方法体; 返回值; } //如: var add = funtion(a,b){ var sum = a+b; return sum; } //(之后使用变量名调用方法) //**第三种方式: //动态方法。 //使用一个js的内置对象 Function var 变量名 = new Function(“参数列表”,“方法体 和 返回值”); (注意,参数和方法体之间是逗号) var add = new Function(“a,b”, “var sum=a+b; return sum”); (之后使用变量名调用函数) //注意,此方式中,可以预先定义好参数列表,和方法体与方法名,在定义方法的时候直接传进来。
Global variables: A variable defined in the script tag, this variable is in the page can be used in the js part - used outside the method, used inside the method, and used in another scipt tag.
Local variables: A variable defined inside a method can only be used inside the method.
javascript advanced tutorial]
The above is the detailed content of What language is JavaScript based on?. For more information, please follow other related articles on the PHP Chinese website!

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

AI Hentai Generator
Generate AI Hentai for free.

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
