Front-end development--face test (JS article)

Source: Internet
Author: User

Tag: Property false Code site onclick ODA HTTP request length type

1. The ACE that intercepts the string abcdace
Alert (' Abcdace '. SUBSTRING (4));

2. Avoiding the same problem of JavaScript multi-person development function
Name space
Closed space
JS modular MVC (data layer, presentation layer, control layer)
Seajs
Variables converted to properties of an object
Object of

3.javascript Object-oriented inheritance implementation
function person (name) {
THIS.name = name;
}

Person.prototype.showName = function () {
alert (this.name);
}

function Worker (name, job) {
Person.apply (this,arguments)
This.job = job;
}
for (var i in Person.prototype) {
Worker.prototype = Person.prototype;
}
New Worker (' SL ', ' coders '). ShowName ();

4. Determine the most frequently occurring character in a string, statistics this number of times
var str = ' ASDFSSAAASASASASAA ';
var json = {};

for (var i = 0; i < str.length; i++) {
        if (!json[str.charat (i)]) {
    ;             Json[str.charat (i)] = 1;
       }else{
                Json[str.charat (i)]++;       }
};
var iMax = 0;
var iIndex = ';
for (var i in JSON) {
        if (Json[i]>imax) {
           / nbsp   IMax = Json[i];
                IIndex = i;
       }
}
Alert (' The most frequently occurring: ' +iindex+ ' appears ' +imax+ ');

5. Write a method to find the byte length of a string;
Assume that a Chinese account is two bytes
var str = ' 222 is ';

Alert (Getstrlen (str))

function Getstrlen (str) {
var json = {len:0};
var re =/[\u4e00-\u9fa5]/;
for (var i = 0; i < str.length; i++) {
if (Re.test (Str.charat (i))) {
json[' Len ']++;
}
};
Return json[' Len ']+str.length;
}

6. Write a method to remove duplicate elements of an array
var arr = [1,2,3,1,43,12,12,1];
var json = {};
var arr2 = [];
for (var i = 0; i < arr.length; i++) {
if (!json[arr[i]]) {
Json[arr[i]] = true;
}else{
Json[arr[i]] = false;
}

if (Json[arr[i]]) {
Arr2.push (Arr[i]);
}
};

for (var i = 0; i < arr.length; i++) {
if (!aa (Arr[i], arr2)) {
Arr2.push (Arr[i])
}
};
function aa (obj, arr) {
for (var i = 0; i < arr.length; i++) {
if (arr[i] = = obj) return true;
else return false;
};
}
Alert (ARR2)

7. Write 3 typical applications that use this
Event: An object that occurs as an onclick this-> event
Constructor this->new out of object
Call/apply Change this

8. How to Deep clone
var arr = [1,2,43];
var json = {a:6,b:4,c:[1,2,3]};
var str = ' SDFSDF ';

var json2 = Clone (JSON);

Alert (json[' C '])
function Clone (obj) {
var onew = new Obj.constructor (obj.valueof ());
if (Obj.constructor = = Object) {
for (var i in obj) {
Onew[i] = Obj[i];
if (typeof (Onew[i]) = = = ' object ') {
Clone (Onew[i]);
}
}
}
return onew;
}

How to detect a variable in 9.JavaScript is a string type? Please write out the function implementation
typeof (obj) = = ' String '
Obj.constructor = = String;

10. In the Web page to achieve a calculation of how much time left in the countdown timer program, the Web page on the real-time dynamic display "xx years left xx days xx xx minutes xx seconds"
var odate = new Date ();
var oyear = Odate.getfullyear ();

var onewdate = new Date ();
Onewdate.setfullyear (Oyear, 11, 31, 23, 59, 59);
var itime = Onewdate.gettime ()-odate.gettime ();

var is = itime/1000;
var IM = Onewdate.getmonth ()-odate.getmonth ();
var iDate =is

11. Please explain what is semantically HTML.
Content uses a specific label, the label will be able to understand the overall layout of the page distribution

12. Why is it more efficient to use multiple domain names to store site resources?
Make sure users are able to open the site at the fastest speed in different regions, where a domain name crash user can also access the site through other depressed

13. Please say three ways to reduce page load time
1, compression css, JS file
2, Merge JS, CSS files, reduce the HTTP request
3, external JS, CSS files on the bottom
4. Reduce DOM operations and replace unnecessary DOM operations with variables whenever possible

14. What is Fouc? How do you avoid fouc?
Due to the introduction of CSS using @import or the existence of multiple style tags and css files at the bottom of the page to make the CSS file loaded in HTML causes the page to blink, flower screen
Load the CSS file with link and put it in the head tag

15. What is the role of the document type? How many types of documents do you know?
affects browser compilation rendering of HTML code
html2.0
Xhtml
Html5

16. What is the difference between browser standard mode and weird mode?
The box model explains the different

17. Closures
A child function can be called externally, and all variables that are connected to the action are saved.

18. Please explain what is the module mode of JavaScript and cite practical examples.
JS modular MVC (data layer, presentation layer, control layer)
Seajs
Name space

19. How do you organize your own code? Do you use the module mode or the classic inheritance method?
Internal: module mode
External: Inheritance

20. How do you optimize your code?
Code reuse
Avoid global variables (namespaces, enclosing spaces, modular MVC). )
Split function to avoid bloated functions
Comments

21. Can you explain how inheritance works in JavaScript?
The child constructor executes the parent constructor and changes this with call\apply
Cloning a method on a parent constructor prototype

22. Please explain how Ajax works in as much detail as possible.
Creating an Ajax Object (Xmlhttprequest/activexobject (microsoft.xmlhttp))
Determine the data transfer mode (Get/post)
Opens the link open ()
Sending Send ()
When the Ajax object completes the fourth step (onreadystatechange) data reception is complete, determine the HTTP response status (status) 200-300 or 304 (cache) execution callback function

Front-end development--face test (JS 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.