The scope of a variable
<script type= "Text/javascript" >
Variables declared in the external function of VAR are global variables
Defined in a function, but Var is not used to declare a global variable
Defined in a function, a local variable is declared with Var
function Squra (num) {
var total; Local variables
Total=num*num;
return total;
}
var total=50; Global variables
Console.log (total);
var Number=squra (20);
Console.log (total);
var global= "global";//global variable
function Test () {
var local= "local";//local variable
Global2= "Global2";//global variable
}
Global variables (less)
var I=1;
//...
var i=2;
function Fun () {
Console.log (i); Output undefined
var i=3; Local variables
Console.log (i); Output 3
}
Fun ();
Console.log (i); Output 2
</script>
Second, internal function
<script type= "Text/javascript" >
Eval accepts a string type parameter, executes the string as code in the context, and returns the result of the execution
var I=1;
Eval ("i=i+1");
Eval ("Console.log (i);");
Convert parseint to integers and parsefloat to floating-point numbers
var i=parseint (22.5);
var k=parseint ("1234blue");
Console.log (i);
Console.log (k);
var i=parsefloat ("22.5float");
Console.log (i);
Escape and Unescape URL encoding and decoding
var url= "http://www.baidu.com/s?name= Millet";
Url=escape (URL);
Console.log (URL);
Console.log (unescape (URL));
</script>
Third, the object
1. Date object:
<script type= "Text/javascript" >
var mydate=new Date (),
Time=mydate.getfullyear (),
Time2=mydate.getmonth () +1,
Time3=mydate.getdate (),
Time4=mydate.gethours (),
Time5=mydate.getminutes (),
Time6=mydate.getseconds (),
Time7=mydate.getday ();
weekly=["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
document.write (time+ "year" +time2+ "month" +time3+ "Day" + "+time4+": "+time5+": "+time6+" "+weekly[time7");
</script>
2.math objects:
<script type= "Text/javascript" >
Random number
0-1 Original
var m=math.random ();
document.write (m+ "<br/>");
0-5
var m=parseint (Math.random ());
document.write (m+ "<br/>");
50-100
var m=parseint (50+math.random () *50);
document.write (m+ "<br/>");
34-58
var m=parseint (34+math.random () *24);
document.write (m+ "<br/>");
/*var K=math.random ();
if (k==1) {
Alert ("Maldives 7 people 7 Days Tour");
}
else{
Alert ("Thank you for participating");
}*/
var k=parseint (Math.random () *10);
Switch (k) {
Case 1:
Alert ("Maldives 7 people 7 Days Tour");
Break
Default
Alert ("Thank you for participating");
Break
}
Absolute
var abs=math.abs (-20);
document.write (abs+ "<br/>");
Rounded
var a=math.round (4.4), b=math.round (5.6);
document.write (A + " " +b+ "<br/>");
The Ceil () method returns the smallest integer greater than or equal to X. (Take the big whole)
var c=math.ceil (1.4);
document.write (c+ "<br/>");
The floor () method returns the largest integer less than or equal to X. (Take small whole)
var d=math.floor (1.6);
document.write (d+ "<br/>");
Returns the Y power of X
var e=math.pow (4,3);
document.write (e+ "<br/>");
</script>
3.Array Array object (not fully):
<script type= "Text/javascript" >
var weekly=["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
for (i=0;i<weekly.length;i++) {
document.write (weekly[i]+ "<br/>")
}
var arr=["title One", "Title II", "title three", "title four";
Arr.push ("Title V", "Title VI");
Arr.unshift ("Title VII", "title VIII");
</script>
<body>
<ul>
<script type= "Text/javascript" >
for (j=0;j<arr.length;j++) {
document.write ("<li>" +arr[j]+ "</li>")
}
</script>
</ul>
</body>
JavaScript Day Fifth