JavaScript Advanced Programming-Phase I

Source: Internet
Author: User
Tags date1

/*
1. Get the logical pixel var pagewidth = Window.innerwidth;var PageHeight = Window.innerheight;console.log ("pagewidth:" + pageWidth); Console.log ("PageHeight:" + pageheight), if (typeof pagewidth! = "Number") {if (Document.compamode = = = "Css1compat") { }}//2, Get window position var LeftPos = (typeof Window.screenleft = = "Number")? Window.screenleft:window.screenx;var Toppos = (typeof window.screentop = = "Number")? Window.screentop:window.screeny;console.log ("Position left:" + LeftPos); Console.log ("Position top:" + toppos);//2, The two comparison operators do not console.log ("= = =:" + (null = = = undefined)); Trueconsole.log ("= =:" + (null = = undefined)); FALSE3, SetTimeout () apply var date1 = new Date (), Console.log (parseint (Date1.gettime ())), var date2 = new Date (); setTimeout (","), Console.log (parseint (Date2.gettime ())), Console.log (Date1.gettime ()-Date2.gettime ()), 4, Cleartimeout ( Func, Time) Apply function demo () {var date = new Date (); Console.log (date);} var t = setinterval (demo, $); SetTimeout ("Clearinterval (t)", 3000); 5, Timer: All DOM elements are rendered before the timing settimeout ("alert (' Deefe ')", 3000),//5, Closure function createfunction () {var result; for (var i = 0; i < ten; i++) {Result[i] = function () {result[i].index = i; return i; }} console.log (Result[0].index); return result;} function createfunction () {var result = new Array (); for (var i = 0; i < i++) {Result[i] = function (num) {return function () {result[ I].index = i; Console.log (i); return num; }; } (i); } return result; Console.log (Createfunction ());//6, trinocular operator Console.log ((x > y x:y) > z? (x > Y x:y): z);//7, Max Math.max () cannot pass in the array, only pass in the parameter column Console.log (max (1)); function Max () {var arr = [12112 , 21, 212, 12, 3213]; return Math.max (arr);} 8, callback function, return the previous operation, each time the result is saved in memory, Occupy memory function Factorial1 (num) {if (num > 0) {return num * FACTORIAL1 (NUM-1); } else {return 1;}}//9, callback function, the result returns, does not occupy the extra memory function Factorial2 (num, total) {if (num > 0) {return total = num * FACTORIAL2 (num -1); } else {return 1; }}var n = 10;console.log ("Factorial1 (" + N + "):" + FACTORIAL1 (n)); Console.log ("Factorial2 (" + N + "):" + Factorial2 (n)); /10, function Interrupt mode functions say () {Console.log ("1");//1 return 0; Console.log ("2"); The function has ended without executing} interrupt loop mode 1.BREAK2.CONTINUE//11, Ecmscript full parser alert (eval ("1+2")),//12, Leap year judgment var j = 1;for (var i = 1; I <= 3 000; i++) {if (GetYear (i)) {Console.log (j + ":" + i); j + +; }}function GetYear (year) {if (year% 400 = = 0 | | (year% 4 = = = 0 && Year% 100! = 0)) {return 1; } else {return 0; }}//13, Push (), pop (), Shift (), unshift () difference var arr = [1, 2, 3];arr.push (4); Console.log ("Push (4):" + arr); 1,2,3,4 add var from the tail arr = [1, 2, 3];arr.pop (4); Console.log (arr); From the tail out of the stack var arr = [1, 2, 3];arr.unshift (4) Console.log (arr); 4,1,2,3 add Var from the head arr = [1, 2, 3];arr.shift (4);Console.log (arr); 2,3 from the tail add//14, + + in front and in the back of the difference var n = 100;alert (++n); 101var m = 100;alert (m++); 100//15, conditional operator Console.log (> 4?) "Yes": "No");


*/

  

JavaScript Advanced Programming-Phase I

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.