Home > Article > Web Front-end > 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.
*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.
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.
//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代码。
–also found in js These statements
if judgment statement
=: ==: � � by by by
--switch(a){ case 1: break; case 2: break; default: … … }
5. js operators
***When subtracting, what is done is subtraction operation.
如: alert(str+1)//结果为1231. alert(str-1)//结果为122.
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。
//–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–There is an attribute length in the array: Get the length of the array.
7. 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”); (之后使用变量名调用函数) //注意,此方式中,可以预先定义好参数列表,和方法体与方法名,在定义方法的时候直接传进来。8. Global variables of js, and local variables
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!