Introduction of a JavaScript method
<! DOCTYPE html>
View CodeIndex.js file
/* **created by Administrator on 2017/8/7. */ alert (123);
View CodeTwo JavaScript variables, constants, and identifiers
<! DOCTYPE html>/*the class capacity of multi-line annotations*/ //the contents of a single line comment //declaring a variable to assign a value /*var i:i=10; var j=20; */ //a row declares multiple variables so that each variable is separated //var name= "Fang", age=18; //JS A semicolon is a delimited symbol of a statement /*var i=12; var j=20; alert (i); Alert (j); */ //If a variable is declared unassigned only, it will print out Undefind /*var x; alert (x); var n=10; var n=3.1415926; */</script>View CodeThree JS data types
<! DOCTYPE html>/*var i=100.89; var s1= "Hello"; var B=false; Console.log (typeof i); Number Console.log (typeof S1); String Console.log (typeof B); Booleam*//*var arr=[111,222, "Hello"]; var obj={"name": "Egon", "Age": "N"} var obj2={name: "Fang", Age: "" "} Console.log (typeof arr); Object Console.log (typeof obj); Object Console.log (obj["name"]); Object Console.log (obj); Object Console.log (OBJ2); *///undefined:1 When a variable only declares an unassigned value to the return value of Undefined; //2 When a function does not return a value, a undefined value is returned by default. /*var A; Console.log (a); Undefined Console.log (typeof a); Undefined*///var a=null;//Console.log (a); Null//Console.log (typeof a); Object //The nan value belongs to the number type: When a string is encountered that is not valid, a Nan data is obtained varS= "Fang"; varret2=+R; Console.log (Ret2); //NaNConsole.log (typeofRet2)// Number</script>View CodeFour-Boolean type
<! DOCTYPE html> console.log (true+2); Console.log (false+2); if (1) { Console.log ("OK"); } </script>View CodeFive operators
<! DOCTYPE html>//x + + ++x<!--varX=10;--> <!--x+=1;-->//x + +: Assign values first in the calculation<!--varret=x++;//x + + (x=x+1)- //++x First calculated and then assigned value<!--varRet1=++x;//++x (x=x+1)--<!--console.log (x);--> <!--console.log (ret);--> <!--console.log (RET1);-->// === !==<!--Console.log (2=== "2");-->//! && | | Logical OR with non-<!--varName= "Egon";--> <!--vargender= "Male";--> <!--if(name== "Egon" && gender== "males") {--> <!--console.log ("success!"); -<!--}-->//+: string concatenationConsole.log ("Hello" + "world"); Console.log ("Hello" +234); </script>View CodeSix-Process Control
<! DOCTYPE html>/*//if expression; Pass//JS if statement//double branch if (expression) {EXECUTE statement}//Multi-branch statement if (expression) {EXECUTE statement} else if (expression) {EXECUTE statement} else { Execute statement}*//*//exercise: Var num=67; if (num>90) {alert ("excellent")} else if (num>80) {alert ("benign")} else if (num>60) {Alert ("pass")} else {alert ("Failed")}*///Switch Case Statement /*var week=3; Switch (week) {case 1:console.log ("Monday"); Case 2:console.log ("Tuesday"); Case 3:console.log ("Wednesday"); Case 4:console.log ("Thursday"); Case 5:console.log ("Friday"); Case 6:console.log ("Saturday"); Case 7:console.log ("Sunday"); } */ //For Loop: //For Loop mode 1: Conditional loop (highly recommended)/*For (Var i=0;i<10;i++) {Console.log (i); }*///For Loop mode 2: Traversing loops/*var arr=[111,222,333]; for (var i in arr) {Console.log (i,arr[i])}*/<!--//While Loop --<!-- while(expression) {--> <!--loop Body--<!--}--> <!--varCount=0;--> <!--varSum=0;--> <!-- while(count<101) {--> <!--sum+=count;--> <!--count++;--> <!--}--> <!--c Onsole.log (sum);-->varSum2=0; for(vari=0;i<101;i++) {sum2+=i; } console.log (SUM2); //Break exits the entire loop, continue exits when the secondary loop</script>View CodeSeven String objects
<! DOCTYPE html>vars= "Hello World"; //Console.log (s.length);Console.log (S.charat (4)); Console.log (S.lastindexof (L)); Console.log (S.indexof (L)); Console.log (S.substr (3,4));//Lo WConsole.log (s.substring (3,4));//l Gu Tou disregard the tailConsole.log (S.concat ("Egon")); </script>View CodeJavaScript Note One