JavaScript Learning --day01

1. Language Features

One kind of literal JavaScript scripting language, is a dynamically typed, weakly typed, prototype-based language, built-in support types.

2. Applications

PC browser / PC software / mobile browser / phone app / micro letter applet / micro-channel public number Development / hardware development / server development / AR / VR / depth learning / Machine Learning

3.js use

Script execution tag content, is executed sequentially, but in accordance with the load 4. The load is asynchronous. Script tag inside the code if there is an error, only only affect the execution of this script tag code. First, the browser parses HTML, parsing the script tag when the tag will execute script code with calls JS engine, will pre-compiles (number of correct grammar and enhance the process variable), and then interpreted.

3.1 Script tag

<Script type = "text / JavaScript"> 
            the console.log ( "Minors are not allowed to enter. 1" ) 
            the console.log (A)
 </ Script>

3.2 Script tag js file references

<script src="js/index.js" type="text/javascript" charset="utf-8"></script>

4. How to declare variables

js is a weakly typed language, it is stated variable, unified declare variables var. If you do not affirm that it will declare a global variable.

Way to declare variables

var b;
var a,b,c;
var name = "username"

Global variables: variables declared in the outermost layer and undeclared variables with the var inside a function, it is a global variable, all global variables are in the window

Local variables: variables inside a function is declared local variables

Js variable naming convention: You must use a letter or _ or $ as the first letter of the alphabet plus _ plus $ plus digital constitute the variable name.

js type:

Value Type: integer / floating point / Infinity / -Infinity / NaN

Type String: "abc", '123'

Object: {}, new object ()

Boolean values: true and false

Undefined: There are affirmed but not assigned.

Null: This is the assignment is empty of content.

5. Functions

5.1 functions defined way

【1】:function count(a){ return x }

【2】:var count = function(){}

5.2 Function parameters

Of function calls, it does not do any testing parameters.

arguments Keywords: Get all the function is called when the

5.3 the return value of the function

Returns the object directly return

Note: If you do not write the return value, the function returns undefined by default

6. array

JavaScript is a variable length array, the contents of which are free to replace, no type of limitation

<! DOCTYPE HTML> 
<HTML> 
    <head> 
        <Meta charset = "UTF-. 8"> 
        <title> </ title> 
    </ head> 
    <body> 
        <Script type = "text / JavaScript"> // . 1, literally amount of ways to create an array var arr1 = [ "Cai Xu Kun", "Guo", "Fan Bingbing" ]
             // 2, new new array () creates an array var arr2 = new new array ( "Apple", 1, "banana", function () the console.log {(123 )}) 
            the console.log (of arr1) 
            the console.log (arr2 is) // Get the array contents 
            console.log(arr1[0])
            console.log(arr1[1])
            arr2[
            
            
            
            
            3 ] () 
            
            // set the array contents 
            arr2 is [3] = 3 
            the console.log (arr2 is) 
            
            // by circulating the contents of the output list 
            for ( var I = 0; I <arr1.length; I ++ ) { 
                the console.log (of arr1 [I]) 
            } 
            
            // queue == "FIFO 
            // stack ==" last out 
        </ Script> 
    </ body> 
</ HTML>
<! DOCTYPE HTML> 
<HTML> 
    <head> 
        <Meta charset = "UTF-. 8"> 
        <title> </ title> 
    </ head> 
    <body> 
        <Script type = "text / JavaScript"> var duilie = [ " Fan Bingbing "," Li Chen " ] 
            the console.log (duilie) //             duilie.push ( 'Cai Xu Kun') 
//             the console.log (duilie) 
//             duilie.push (" Guo ") 
//             the console.log (duilie) // the Push to add content to an array of last             duilie.shift (); 
            console.log (duilie) 
            duilie.unshift ( "Yao Ming " ) 
            console.log (duilie)
            

            
 
            duilie.pop ()
            the console.log (duilie) 
            duilie.push ( "Madison" ) 
            duilie.push ( "Kobe" ) 
            the console.log (duilie.slice ( 0,2 )) 
            the console.log (duilie) 
            the console.log (duilie.splice ( 0 2, "library", "Durant" )) 
            the console.log (duilie) 
            
            // first element of the array to remove 
            / * duilie.shift () 
            the console.log (duilie) * / 
            
            // without the array of the last element 
            / * duilie.pop () 
            the console.log (duilie) * / 
            
            // inserted in front of the first data element of the array 
            / *  duilie.unshift ( "LEI")
            the console.log (duilie) * /
            
             // in duilie.slice (0,2), cut in the array begins with index 0 and index 2 to the cut position, excluding 2; 
            / * the console.log (duilie.slice (0 , 2)) 
            console.log (duilie) * / 
            
            // splice can add or delete the specified elements, duilie.splice (delete or add the location of the index, how many elements are deleted, additions (optional)) 
            / * Console .log (duilie.splice (0,2, "Dilly Reba", "Gülnezer Bextiyar")) 
            the console.log (duilie) * / 
            
            // merge the two arrays 
            duilie = duilie.concat ([ 'grapes' , 'banana', "Sydney" ])
             // equivalent for loop 
//             duilie.forEach (function (Item) { 
//                 the console.log (Item) 
//             })
            
             
        </ Script> 
    </ body> 
</ HTML>

 

Guess you like

Origin www.cnblogs.com/WhiperHong/p/10945371.html