Reprinted from: http://www.jianshu.com/p/87fa2c21039a
Note: In fact, in the real interview, the interviewer often uses the routine from difficult to easy, that JS and jQuery is the most important. As well as some questions about the project and the technology used.
JavaScript
What is a closure and why do you use it?
A closure is a function that can access the variables of an external function.
function aa(x){ var num=1; function bb(y){ console.log(x+y+(++num)); }}Copy the code
A bb function of a aa function is a closure. A BB function can take local variables and arguments of a AA function. A typical closure would look like this, with a function defined in a function as its return value
function aa(x){
var num=1;
function bb(y){
console.log(x+y+(++num));
}
return bb;
}Copy the code
Another function of closures is to isolate scopes, as shown in the following code
for(var i=0; i<2; i++){ setTimeout(function(){ console.log(i); }, 0); }Copy the code
The result of this code is 2,2 instead of 0,1, because by the time the for loop comes out and setTimeout is executed, the value of I has changed to 2.
Talk about understanding This object
- This is a js keyword. The value of this can change depending on where the function is used.
- But the general rule is that this refers to the object on which the function is called.
- This is the Global object. As a method call, then this is the object
Event is? What’s the difference between IE and Firefox’s event mechanism? How do I stop bubbling?
- An action we take on a web page (some actions correspond to multiple events). For example, when we click a button an event is generated. Is behavior that can be detected by JavaScript.
- Event handling mechanism: IE is event bubbling, Firefox is event capture;
- ev.stopPropagation();
JavaScript scope and scope chain?
JavaScript is refers to the scope of the variable scope, within the scope of the function of the parameter, arguments and local variables, functions, external and internal scope as the scope of the link layer upon layer form the scope chain, when inside the function to access a variable, find himself first did within the scope of this variable, If not, go to the scope of the object’s prototype object. If not, go to the scope of the object’s scope. Until the scope of the window is specified, each function is declared with an external scope by default.
var t=4; function aa(){ var num1=12; funciton bb(){ var num2=34; console.log(t+" "+num1+" "+num2); }}Copy the code
The process of bb looking for t is to first look in its own internal scope and find it not found, then look in the nearest external variable of BB, that is, the internal scope of AA, still not found, then look in the scope of Window and find it
“Use strict”; What does that mean? What are the advantages and disadvantages of using it?
ECMAscript 5 adds a second mode: “Strict mode”. As the name suggests, this mode makes Javascript run under more stringent conditions. The main objectives of the Strict Mode are as follows:
Advantages:
- Eliminate some unreasonable and inaccurate Javascript syntax, reduce some weird behavior;
- Eliminate some unsafe code operation, to ensure the safety of code operation;
- Improve the efficiency of the compiler, increase the running speed;
- Set the stage for future versions of Javascript. Note: After testing IE6,7,8, and 9 do not support strict mode.
Disadvantages:
JS on websites are now compressed, some files are in strict mode and others are not. These files are merged into the middle of the file, not only does it not indicate the strict mode, but it wastes bytes after compression.
What exactly does the new operator do?
1. Create an empty object that is referenced by this and inherits the prototype of the function. Properties and methods are added to the object referenced by this. 3. The newly created object is referenced by this and returns this implicitly.
var obj = {};
obj.__proto__ = Base.prototype;
Base.call(obj);Copy the code
In Javascript, there’s a function that performs an object lookup that never looks up the prototype. What’s that function?
hasOwnProperty()
What do you know about JSON?
JSON(JavaScript Object Notation) is a lightweight data interchange format. It is based on a subset of JavaScript. {‘age’:’12’, ‘name’:’back’}
What are the ways to lazily load JS?
Defer and Async, create the DOM dynamically (most used), and load JS asynchronously on demand
What is Ajax? What are the pros and cons?
Advantages:
- The asynchronous mode improves user experience
- Optimized transfer between browser and server to reduce unnecessary data round-trip and reduce bandwidth usage
- Ajax runs on the client side, taking over some of the work that would have been done by the server, reducing the load on the server under a large number of users.
The biggest feature of Ajax: Ajax enables dynamic non-refresh (partial refresh)
Disadvantages: 1. Ajax does not support the browser back button. Security Issues AJAX exposes the details of the server interaction. 3. Weak support for search engines. 4. Break the exception mechanism of the program. 5. It is not easy to debug.
How to solve cross-domain problems?
Jsonp (using the cross-domain capability of script tags) cross-domain, WebSocket (a new feature of HTML5, a new protocol) cross-domain, set up proxy servers (servers that request data for us from servers of different sources), CORS (cross-source resource sharing, Cross Origin Resource Sharing), IFrame across domains, postMessage(pages containing IFrame pass messages to iframe)
How do you do modularity? Execute the function immediately without exposing private members
Var module1 = (function(){var _count = 0; Var m1 = function(){//... }; Var m2 = function(){//... }; Return {m1: m1, m2: m2}; }) ();Copy the code
What are the methods of asynchronous loading?
(1) defer, which only supports IE (2) async: false (true by default); (3) Create script and insert it into DOM. After loading, callBack
The difference between documen.write and innerHTML
- Document.write can only redraw the entire page
- InnerHTML redraws a part of the page
The difference between.call() and.apply()?
Call (sub,3,1) == add(3,1); alert(4); Note: functions in js are actually objects, and Function names are references to Function objects.
function add(a,b) { alert(a+b); } function sub(a,b) { alert(a-b); } the add. Call (sub, 3, 1);Copy the code
What is the difference between Jquery and Jquery UI?
- JQuery is a js library that provides functions such as selectors, property modification, event binding, etc.
- *jQuery UI is a plug-in designed on the basis of jQuery and using the extensibility of jQuery.
- Provides some common interface elements, such as dialog boxes, drag behavior, resizing behavior, and so on
How to convert an array to a JSON string in jquery, and then back again?
JQuery does not provide this functionality, so you need to write two jQuery extensions first:
$.fn.stringifyArray = function(array) {
return JSON.stringify(array)
}
$.fn.parseArray = function(array) {
return JSON.parse(array)
}
然后调用:
$("").stringifyArray(array)Copy the code
Optimization for jQuery?
- The performance of class-based selectivity is expensive compared to Id selectors because you need to traverse all DOM elements.
- DOM, which is frequently manipulated, is cached before manipulation. It is better to use Jquery’s chain call.
Such as:var str=$("a").attr("href"); *for (var i = size; i < arr.length; i++) {}
The for loop looks for the.length property of the array (arR) on each loop. Setting a variable to store this number at the beginning of the loop can make the loop run faster:
for (var i = size, length = arr.length; i < length; i++) {}
Variable declaration enhancement in JavaScript?
Variables declared by var in a function are preloaded before the function body is executed
var num=1;
function aa(){
console.log(num); //undeifned
var num=2;
console.log(num); //2
}
aa();Copy the code
(num = aa, num = aa, num = aa, num = aa, num = aa, num = aa, num = aa, num = aa, num = aa, num = aa, num = aa
function aa(){ var num; console.log(num); //undefined num=2; console.log(num); / / 2}Copy the code
Which operations cause memory leaks?
- A memory leak is any object that persists after you no longer own or need it.
- The garbage collector periodically scans objects and counts the number of other objects that refer to each object. If the number of references to an object is zero (no other object has ever referenced it), or the only references to the object are cyclic, then the object’s memory is reclaimed.
- Using a string instead of a function as the first argument to setTimeout causes a memory leak.
- Closures, console logging, loops (a loop is created when two objects reference and retain each other)
How do I determine whether the script is currently running in a browser or node environment? (ali)
Check whether the Global object is window. If not, the script is not running in the browser
Of course, in an interview, in addition to knowing these basic knowledge, many times you need to know your work experience, do you have? Here are some of the problems, solutions, and thinking patterns in work and projects
Other problems (some of the problems I have encountered and summarized, for your reference)
- What is the most difficult technical problem you have encountered? How did you solve it?
- What libraries are commonly used? Common front-end development tools? What applications or components have you developed?
- How to reconstruct the page?
- List the features that make Internet Explorer different from other browsers.
- 99% of websites need to be refactored. What book is that?
- What is graceful degradation and progressive enhancement?
- How do WEB applications actively push Data from the server to the client?
- What is your role in your current team and what is your obvious impact?
- What other technologies do you know besides the front end? What is your greatest skill?
- How to design a burst large-scale concurrency architecture?
- What do you think is a Full Stack developer?
- Can you tell me one of your favorite works?
- What are your strengths? What are the disadvantages?
- How do you manage the front end team?
- What are you studying recently? Can you tell me where you see yourself in the next three to five years?
What are the advantages and disadvantages of Node?
advantages
- Because Node is event-driven and non-blocking, it is ideal for handling concurrent requests, so proxy servers built on Node perform much better than servers implemented with other technologies, such as Ruby. In addition, the client code that interacts with the Node proxy server is written in the javascript language, so both the client and server sides are written in the same language, which is a nice thing.
disadvantages
- Node is a relatively new open source project, so it’s not very stable, it’s always changing, and it doesn’t have enough third-party library support. It looks like Ruby/Rails back in the day.
What performance optimization methods do you have? (See Yahoo’s 14 Performance Optimization Principles)
(1) reduce the number of HTTP requests: CSS Sprites, JS, CSS source compression, image size control appropriate; Web Gzip, CDN hosting, data cache, picture server. (2) Front-end template JS+ data to reduce bandwidth waste caused by HTML tags. Front-end variables are used to save AJAX request results, so local variables are not required for each operation to reduce the number of requests. (3) Use innerHTML instead of DOM operations to reduce the number of DOM operations and optimize javascript performance. (4) Set className instead of style when there are many styles to set. (5) Use less global variables and cache the results of DOM node search. Reduce I/O read operations. Avoid using CSS Expression, also known as Dynamic properties. (7) Image preloading, style sheets at the top, scripts at the bottom with time stamps. (8) Avoid using tables in the main layout of a page. Tables are not displayed until the content is fully loaded, which is slower than div+ CSS layout.
What are the HTTP status codes? What does it mean to represent separately?
100-199 Indicates the actions that the client should take. 200-299 Indicates that the request is successful. 300-399 Is used for files that have been moved and is often included in the location header to specify new address information. 400-499 Indicates errors on the client. The current request cannot be understood by the server. 401 The current request requires the user to verify that the 403 server understands the request but refuses to execute it. 500-599 is used to support server errors. 503 -- Service unavailableCopy the code
What happens when a page is loaded and displayed from the time the URL is entered? (The more detailed the process, the better)
- Find the browser cache
- DNS resolves, searches for the IP address corresponding to the domain name, redirects (301), and sends the second GET request
- The HTTP session is performed
- Client sends headers (request headers)
- Server feedback header (response header)
- The HTML document starts to download
- A document tree is created to specify the MIME type of the file required by the tag request
- File display {browser side of the work is roughly divided into the following steps: load: according to the URL for domain name resolution, to the server to initiate a request, receive files (HTML, JS, CSS, images, etc.). Parsing: Parses the loaded resources (HTML, JS, CSS, etc.) and suggests the corresponding internal data structures (such as HTML DOM tree, JS property sheets, CSS style rules, etc.)}
What development tools do you use and why?
What editor have you used and how and why you converted from the time you got to the front end to the time you learned how to use it
How do you understand the position of front-end interface engineer? What are its prospects?
- The front end is the programmer closest to the user, closer than the back end, database, product manager, operations, and security.
- Interface interaction
- Improve user experience
- With Node.js, the front end can do some things on the server side
- The front end is the programmer closest to the user, and the power of the front end is to evolve a product from a 90 to a 100 or better,
- Participated in the project, completed the effect drawing quickly and with high quality, accurate to 1px;
- Communicate with team members, UI design, product manager;
- Good page structure, page reconstruction and user experience;
- Hack, compatible, write beautiful code format;
- Server optimization, embrace the latest front-end technology.
How do you manage your projects?
- The initial team must determine the global style (globe.CSS), encoding pattern (UTF-8), etc.
- The writing habits must be consistent (for example, each style is written in a single line using inheritance);
- Annotation style writer, all modules are timely annotation (annotation key style call place);
- Annotate pages (e.g. start and end of page modules);
- CSS and HTML should be stored in parallel folders and named in the same way (for example, style.css).
- JS folders store English translations named according to the JS function.
- Png8 format files are used as far as possible to integrate together to facilitate future management
What are the most popular things these days? What websites do you visit?
Node.js, MongoDB, NPM, MVVM, MEAN, three.js, Angular, React, Vue Github, Zhihu, MDN, ES6, Bootstrap, git
Mobile terminal (Android IOS) how to do a good user experience?
- Clear visual vertical lines, grouping of information, extreme subtraction,
- Use selection instead of input, labels, and text layouts,
- Relying on clear text for password confirmation, reasonable keyboard utilization,
In the interview, it’s really an interactive process, not only answering questions, but also taking the opportunity to take the initiative and ask questions about the company?
Ask the company questions:
- What are the latest Web front-end technologies (future directions) you are looking at?
- How does the front end team work (the process of implementing a product)?
- What is the company’s salary structure? (Find out exactly where you are at.)
- What is the promotion mechanism in the company? (See your self-motivated stability)
The last words
The enterprise interview basically is to see you can stem. It will be difficult for companies to hire a suitable person, and it will not be easy to eliminate you.
If they pick on you, prove they have an intention to hire you. Otherwise, they won’t waste time picking on you. The main reason they pick on you is because they want to squeeze you for money. There are no professional interviewers.
Just because I interviewed this one doesn’t mean he has to hire me. There are many other companies waiting for you to choose. Take a long-term view and make sure you get the salary you are satisfied with.
The interview is a process of uncovering both sides of the lie, you can deceive each other, prove that you win.
Change the mentality to interview, not the enterprise is picking you, but you are picking the enterprise. Raise your confident head, brave to meet the challenge! Your future belongs to you!
~END~
Did this article help you? Welcome to join the front End learning Group wechat group: