Today’s content

1. The JavaScriptCopy the code

JavaScript:

* Concept: a client-side scripting language that runs in the client-side browser. Each browser has JavaScript parsing engine * scripting language: does not need to compile, can be directly interpreted by the browser performed * features: * can enhance the user and HTML page interaction process, can control HTML elements, let the page have some dynamic effect, enhance the user experience. * Development history of JavaScript: 1. In 1992, Nombase developed the first client-side scripting language for form validation. Named: C--, later renamed: ScriptEase 2. In 1995, Netscape developed a client-side scripting language: LiveScript. Later, experts from SUN Company were invited to modify LiveScript and named it JavaScript. 3. In 1996, Microsoft developed JScript language by copying JavaScript. ECMAScript, which unifies the coding of all client-side scripting languages. * ECMAScript: A standard for client-side scripting language 1. Internal JS: * defines <script>, the body of the tag is JS code 2. External JS: * Defines <script>, importing external JS files via the SRC attribute * Note: 1. <script> can be defined anywhere on an HTML page. But the location of the definition affects the order of execution. 2. <script> can define more than one. 1. Single-line comment: // Comment content 2. Multi-line comment: /* comment content */ 3. Data type: 1. Original data type (basic data type) : 1. Number: number. Integer/decimal /NaN(not a number a number type that is not a number) 2. String: a string. String "ABC" "a" 'ABC' 3. Boolean: true and false 4. null: placeholder for an empty object 5. undefined. If a variable has no initialization value, it is assigned undefined by default. Reference data types: objects 4. Variables * Variables: A small chunk of memory that stores data * The Java language is strongly typed, while JavaScript is weakly typed. * Strong type: When a variable storage space is opened, it defines the data type that the space will store in the future. Only fixed types of data can be stored * Weak type: When creating variable storage space, the future storage data type of the space is not defined, and data of any type can be stored. * Syntax: * var variable name = initialization value; * typeof operator: gets the typeof a variable. 5. Operator 1. Unary operator: operators with only one operand ++, --, +(plus sign) * ++ --: Since the increase (from decreases) * + + (-) in the former, the first since the increased (from) reduction, operation * + + (-) in the back, again before operation, then the increase (the decrement) * + (-) : plus or minus * note: In JS, if the operand is not of the required type, then the JS engine automatically converts the operand to the literal value. If the literal is not a number, convert to NaN (a number that is not a number) * Boolean Convert to number: true to 1, false to 0 2. Arithmetic operator + - * / %... 3. Assign operator = += -+.... 4. Comparison operator > < >= <= == ===(all equal) * comparison method 1. Same type: Direct comparison * String: compares in lexicographical order. Compare bit by bit until you get the size. 2. Different types: Perform type conversion first and then compare * === = : all equals. Check the type before comparing. If the type is different, return false 5. Logical operators && | |! * Other types to Boolean: 1. Number: 0 or NaN: false, other types of Boolean: true 2. String: true except for empty string ("") 3. Objects: All objects are true 6. Ternary operators? Var a = 3; var b = 4; var c = a > b ? 1-0. * Syntax: * expressions? Value 1:2; * Determine the value of the expression, 1 if true and 2 if false; 6. Flow control statement: 1. else... Byte int shor char, enumeration (1.5),String(1.7) * switch(variable): case value: * In JS, the switch statement can accept any primitive data type. While 5. for 7.js special syntax: 1. End, if there is only one statement in a line; You can omit (not recommended) 2. Use the var keyword to define a variable. * Use: The defined variable is a local variable. * Do not use: the defined variable is a global variable. Exercise: 99 times table <! DOCTYPE HTML > < HTML lang="en"> <head> <meta charset=" utF-8 "> <title>99 times table </title> <style> TD {border: 1px solid; } </style> <script> document.write("<table align='center'>"); For (var I = 1; var I = 1; i <= 9 ; i++) { document.write("<tr>"); for (var j = 1; j <=i ; j++) { document.write("<td>"); / / output 1 * 1 = 1 document. Write (I + "*" + j + "=" + (I * j) + "& have spent &nbsp; &nbsp;" ); document.write("</td>"); } /*/ document.write("<br>"); */ document.write("</tr>"); } //2. Complete table nesting document.write("</table>"); </script> </head> <body> </body> </html> 2. Var fun = new Function(formal argument list, method body); Function (){function(){function(){function()} 2. Method: 3. Attribute: Length: represents the number of parameters 4. The method definition is that the type of the parameter is not written, nor is the return value type. Method is an object. If you define a method with the same name, the method will be overwritten. In JS, the method is called only with the name of the method, not with the parameter list. There is a hidden built-in object (array) in the method declaration, arguments, that encapsulates all the actual arguments 5. Call: method name (actual argument list); Create: 1. Var arr = new Array(element list); Var arr = new Array(default length); Var arr = [element list]; 2. Method JOIN (parameter): Concatenates the elements of the array into the string push() with the specified delimiter, and returns the new length. 3. Attribute length: the length of the array 4. 2. In JS, array length is variable. Create: var Date = new Date(); 2. Method: toLocaleString() : returns the time of the current date object in the local string format getTime(): gets the value of milliseconds. Returns the millisecond value difference between the current time of the specified object description and zero on January 1, 1970. * Features: The Math object is not created and is used directly. Math. Method name (); 2. Method: Random (): Returns a random number between 0 and 1. Ceil (x) : rounding of logarithms. Floor (x) : Logarithms are rounded down. Round (x) : Round the number to the nearest whole number. 3. Properties: PI 6. Number 7. String 8. RegExp: regular expression object 1. Regular expression: Defines the composition rules of a string. 1. A single character: [], such as: [a] [ab] [a zA - Z0-9 _] * special symbols represent a single character of special meaning: \ d: a single numeric characters [0-9] \ w: a single word character [a zA - Z0-9 _] 2. Quantifier symbols:? : 0 or 1 times * : 0 or more times + : 1 or more times {m,n}: m<= Quantity <= N * m If default: {,n}: maximum n times * n if default: {m,} at least m times 3. Start end symbol * ^: start * $: end 2. Re object: 1. Create 1. Var reg = new RegExp(" regular expression "); 2. Var reg = / regular expression /; 2. Method 1. test(parameter): verifies that the specified string conforms to the specification of the re definition. Features: Global objects. Methods encapsulated in Global can be called without objects. The method name (); 2. Method: EncodeURI (): URL encoding decodeURI(): URL decoding encodeURIComponent(): URL encoding, encoding more characters decodeURIComponent(): URL decoding parseInt(): string to number * Check whether each character is a number one by one until it is not, and convert the preceding digit part to number isNaN(): check whether a value isNaN * NaN. NaN's participation in the == comparison all asks false eval(): speaks JavaScript strings and executes them as script code. 3. URL encoding spread wisdom podcast = %E4%BC%A0%E6%99%BA%E6%92%AD%E5%AE%A2 * BOM * DOMCopy the code