What language is JavaScript based on?

青灯夜游
Release: 2023-01-07 11:43:49
Original
4125 people have browsed it

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.

What language is JavaScript based on?

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>`
Copy after login

Second type:
  --Introducing external files:
  -Create a .js file.

-- <script type="text/javascript" src=" 外部文件地址 "> </script>
Copy after login

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代码。
              
Copy after login

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:
       … …
 }
Copy after login

5. js operators

=: x =y; equal to: x=x y;

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.
Copy after login

Note: When str is not a number, the subtraction operation will prompt an error.

var str = “abc”;
alert(str-1);//结果为:提示NaN: 表示这不是一个数字。
Copy after login

**boolean can also perform mathematical operations
If set to true, when performing mathematical operations, the equivalent value is: 1

If set to false, when performing mathematical operations, the equivalent value will be: The value is: 0

The difference between == and ===

They are both used to make equality judgments,

// == 比较的是 值
// === 比较的是 值 和 类型
如: var i = “5”;
   i5 // true
   i=5 // false。
Copy after login


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
Copy after login

–There is an attribute length in the array: Get the length of the array.

–The length of the array is variable.

–Arrays can store different types of values

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”);
                (之后使用变量名调用函数)
            //注意,此方式中,可以预先定义好参数列表,和方法体与方法名,在定义方法的时候直接传进来。
Copy after login
8. Global variables of js, and local variables

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.

[Recommended learning:

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!