On-line collation of JS face questions

Source: Internet
Author: User

The following are compiled online JS interview questions, the answer is for reference only.

/2, intercept the string ABCDEFG EFG
Alert (' ABCDEFG '. SUBSTRING (4));

3, judge the most frequently occurring characters in a string, count this number
/*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) {
IMax = Json[i];
IIndex = i;
}
}
Alert (' The most frequently occurring: ' +iindex+ ' appears ' +imax+ '); */

4,ie and FF scripting compatibility issues
/*obj.addeventlistener (SEv, FN, false);
Obj.attachevent (' on ' +sev,fn);
Detachevet
RemoveEventListener
domcontentloaded
onReadyStateChange Complete
Dommousescroll FF
OnMouseWheel non-FF
Event.wheeldelta roll up 120 down-120
Event.detail up-3 down 3
OBJ.GETCURRENTSTYLE[ATTR]
getComputedStyle (Obj,false) [attr]
XMLHttpRequest
ActiveXObject (' mircorsoft.xmlhttp ')
FF local can set read cookie other not
Event EV
Event Source
srcelement| | Target
toelement| | Relatedtarget
Obj.setcapture (); only IE recognized
Obj.releasecapture (); */

5, avoid the problem of the same name of JavaScript multi-person development function
/* Namespace
Closed space
JS modular MVC (data layer, presentation layer, control layer)
Seajs
Variables converted to properties of an object
Object */

6,javascript inheritance implementation in object-oriented
/*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 (); */

7,FF below to implement outerHTML
/*var odiv = document.createelement (' div ');
var oDiv1 = document.getElementById (' Div1 ');
var owarp = document.getElementById (' warp ');

Owarp.insertbefore (Odiv, ODIV1);
Odiv.appendchild (ODIV1);
var sOut = odiv.innerhtml;
Owarp.insertbefore (ODiv1, Odiv);
Owarp.removechild (ODIV);
alert (sOut); */


8, 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;
}*/

9, write a method to remove the repeating 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) */

10, write out 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*/

11. How to Deeply 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 12,javascript is a string type? Please write out the function implementation
typeof (obj) = = ' String '
Obj.constructor = = String;

13, 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*/

2. Can you describe the workflow in which you create a Web page?

3. Can you describe the difference between progressive enhancement and graceful demotion?

4. Please explain what semantic html is.
Content uses a specific label, the label will be able to understand the overall layout of the page distribution

6. How do you optimize your website's files and resources?

7. 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

8. 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 as much as possible */

9. 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 so that CSS files loaded in HTML causes the page to blink, flower screen
Load the CSS file with link and put it in the head tag */

10. What is the role of the document type? How many types of documents do you know?
/* Affects the browser's compilation rendering of HTML code
html2.0
Xhtml
html5*/

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

1.* have you used those JavaScript libraries?
jquery Seajs Yui

2. Hash table
Data model with hash (map) attributes

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

4. Please explain what is the module mode of JavaScript and cite practical examples.
/*JS modular MVC (data layer, presentation layer, control layer)
Seajs
Namespaces */

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

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

10. Can you explain how inheritance works in JavaScript?
/* The parent constructor is executed in the child constructor, and the This is changed with call\apply
Cloning a method on a parent constructor prototype */

11.useraget.nav

12. Please explain how Ajax works in as much detail as possible.
/* Create 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 */

On-line collation of JS face questions

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.