JavaScript Review notes

Source: Internet
Author: User
Tags arithmetic float double logical operators object model

/*javascript: Used to write effects on the page, and HTML, CSS is the same browser parsing JavaScript language: First, JS how to run (Javascript,jscript,vbscript,applet ... Second, the output alert (what type can be); You can do debugging with document.write ("string"); third, how to use JS in HTML document &LT;SCRIPT&G        T;</script> the JS syntax into HTML, you can use more than one, and each one is associated.        <script src= "Demo.js" ></script> the introduction of external JS files, multiple files are interlinked, but there are sequencing. <a href= "Javascript:alert (" 111111 ");"            ></a> Execute JAVASCIRPT Program event when you click a link: Run JS JS syntax when event is triggered: Naming specification: 1. Naming must be meaningful.            2. Letters, numbers, underscores, and $ symbols that do not begin with a number.        3. Cannot be a keyword or a reserved word.        Case: JavaScript is strictly case-sensitive camel-named: variable names and functions, the first word lowercase, and the first letter of each word capitalized showcolor ();        Object: The first letter of each word must be capitalized Data (); new object (); Semicolon: The structure definition statement is followed by a semicolon. The IF () {} for () {} function () {} feature executes the statement with a semicolon appended to it.        var a=1, if there is a carriage return where the line can be omitted (because JS thinks the newline represents the end of the statement), but the recommendations are added semicolons.        Note: Write comment document//single line multi-row four, variable var a=10;                Note: Declared variables are stored in memory for use at any time, and memory is freed only when the browser is closed, unlike other languages. var variable name = value; Note: jaVascript is a weakly typed language (same as PHP) var a=10;        Statement a=10;        Assignment five, data type 1.number (int float double) includes shaping floating-point types, which are evaluated separately by shaping and floating-point types.                2.string (string char) 3.boolean 4.object (object array null) Note: When using a variable with 5.undefind not declared Integer: var a=10; decimal var a=045; octal var a=0xff; Hex float: Floating-point number is approximate, not            Can be used to judge two floating-point numbers equal to (0.1=0.0999999999) var f=10.5;            var f=10.55;                var f=10.5e+10;            The string "" "is no different, all escapes can be used with the + sign to concatenate the string six, the operator and the expression arithmetic operator            +-*/% + +--Var a=10+5+ "12ABC" +20//1512abc20 all string operations in JavaScript are handled as strings. % (the positive and negative values of the final value and the positive and negative) for the remainder, it is best to be an integer, if there is a floating-point number, the value is not meaningful.            4%2.7 value of 1.29999998 assignment operator = + = *=/=%= conditional operator > < = = = >= <= = =!==            On both sides the best is the same type, compared with the value of the Boolean var a=false; if (a) {aLert ("111");}        Else{alert ("000");} Logical Operators && | | ! ^ bit arithmetic symbols (used in C language for encryption and algorithms) >> >>> << |                & ~ Other?: Vii. Process Control sequential structure conditional structure/branching structure/selection Structure 1. Single Branch if (Boolean) {                } 2. Dual Branch if (Boolean) {}else{} 3. Multi-Channel Branch if (Boolean) {}else if (Boolean) {}}else if (Boolean) {} is used to                        Range switch (variable) {//Variable value is best used for shaping or character-type case: value 1; expression 1;                    Break                    Case: value 2; expression 2; break;                Default                    A single value matches 4. Nested branch if (bool) {if (bool) {...      }} cyclic structure condition loop (JS with not much) var i=0;      while (i<100) {document.write ("# # #");            i++; } do-while () Count Loop St:for (Var i=1;i<=9;i++) {for (Var j=0;j<=9;j++) {if (j==5) break St;//Exit double loop method, output 5 cases after jumping out of document.write (j+ "*" +i+ "=" + (            J*i)} document.write ("<br>"); The break exits the loop continue exits the loop eight, function: is a section of the "named" Code snippet function that completes the "specified function" is used only with "call", and is called by the function name (before the declaration can be After declaration) function test (obj) {//obj is the return value of the formal parameter function segment;//Exit Function} test (x);        When the X argument function name does not add (), the function name represents the whole function alert (typeof (Test));//function alert (test);//function can be considered as a variable, the function declaration of the Popup test ()        var demo=test; Demo (x);//and test (x) Effect 1. function name 2. Parameter 3. function Body (function) 4. The return value (optional) has a return value to be called a function, and no return value can be called a procedure callback function: function pass       Pass-through variables do not solve the problem, by passing the function to complete nine, object (first letter capital) 1. Object-based operation (object-oriented mainly has three main features: encapsulation, inheritance, polymorphism) 2. Use an object to complete a related operation, as a whole string object a mathematical object array object time pairs            Contents of the Image object: 1. Properties (variables) 2. Method (function) Declares the object, uses the object, and uses the system object; Ten, built-in JS object important: Array object string object property: Length method: Bold Put Html<b                    > mark the text placed in the object at both ends var str1= "abc"; Str2=str1.bold ();//<b>abc</b> CharAt returns the character at the specified index position replace returns the complex of the string after the literal substitution based on the regular expression                System.                    LastIndexOf return the last occurrence of a string in a String object match uses the regular expression pattern to perform a lookup on a string substr returns a substring of the specified length starting at the specified position                var s= "Acdscdgaefes"; var ss=s.substr (2,6);//DSCDG toString                toUpperCase all letters are converted to uppercase letters toLowerCase all letters are converted to lowercase Math object properties: E, PI method: ABS absolute Ceil returns the smallest integer greater than or equal to its numeric parameter                Floor returns the largest integer less than or equal to its numeric parameter random returns a pseudo-random number from 0 to 1 round returns the integer that is closest to the given numeric expression.                Max returns the larger of the numeric expression.                Min Returns the lesser of the numeric expression.                var i=300; var X=math.max ( -6,math.min (6,i)); x between positive 6 minus 6 RegExp Object data Object Global Object understanding: Boolean Pair An array of array objects, such as the function object number object, Object 11.                Function: The array declaration is required as long as the batch data is used; declaring an array: 1. Quickly declare var arrs=[item1,item2,item3,,,,,,];                var arrs=[[1,2,3],[4,5,6],[7,8,9]];            2. Use the Array object var arr=new array ("Item1", "item2", "item3"); Property: Length, prototype method: Concat join array Join array element pop shift in divisor group The last element and returns reign title shift shifts the first element in the array and returns the reign title push adds the new element to a stop reverse returns an element order reversed        The Array object        Slice returns an array of Arrayobj.slice (Start,end);        Sort sorting splice one or more elements in an array the toString returns the string representation of the object objname.tostring (binary);D the om:dom operation:                Event: One, Event Source: Any one HTML element body,div,button,p,a,h1 and so on two, event: Your action mouse event: click Dbclick Textcontentmenu (in body) Text menu (right mouse button event) <body oncontextmenu= "return test ()" &G                        T                                <script> function Test () {alert ("OK");                            return false;                 } </scirpt> </body> mouseover mouseout MouseDown MouseUp MouseMove Keyboard event: KeyPress keyboard event only                Ability to get numbers and letter keys (excluding function keys, arrow keys, etc.) KeyUp all keys KeyDown all key documents: LoAfter the ad page loads, the trigger unload Beforeunload closes before the form: Submit Focus Blur Change Form content changes other: Scroll roll Event selected Select event three, event handling three methods plus event: 1. Tag <p on event =                    "Event handlers" ></p> 2.<script></script> tags riga <script> Object. On event =function () {event handler} </script> 3. Infrequently            Use <script for= Event ID event= events > Event Handlers </script> Event Objects: Event object properties that occur when an event occurs: 1.srcElement Event source object, do not need this general with this, but can be used to resolve compatibility <p onclick= "show ()" >aaaaa</p> &L                t;script> function Show () {window.srcelement.innertext= "AAA";    } </script>        2.keyCode event occurs when the keyboard code <body onkeydown= "show ()" > <script> fu                    Nction Show () {alert (event.keycode);            } </script> </body> 3.clientx,clienty 4.screenx,screeny            5.returnValue Window.event.returnvalue=false; 6.cancelBubble de-bubbling <body onclick= "one ()" >  function One () {Alert ("body click");                        } function () {Alert ("img click");  Window.event.cancelbubble=ture;                    When the bubbling event occurs, the program executes here and is not executed down.        } </script> </body> BOM: Browser object model One, the browser itself has some objects, these objects can be used without creating;              1.window: Properties of the current browser form:      Status Opener closed method: Alert ();  Confirm (); onclick= "return confirm (" Are you sure to delete it? ")                ");"                                    SetInterval ();                        var num=0;                    var dir=1; SetInterval (function () {if (num>40| |                        num<0) {dir=-1*dir;                        } Num+=dir;                        var space= "";                                                                    for (Var i=0;i<num;i++) {space+= "";//to scroll to the right by adding spaces;}                                                        window.status=space+ "Scrolling display of content";},100);                Clearinterval ();                Setimeout ();                Cleartimeout (); Open (); window.open ("url", "Windowname", "windowfeature");*/

JavaScript Review notes

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.