Seeing that many friends are asking for front-end written test questions, I collected some interview questions for you. These are all the latest questions in 2017. I hope they will help you improve your skills. I also wish you can get into the company you want to work in.
This article collects and analyzes the latest 2017 front-end written test questions in more detail. Share it with everyone for your reference. The details are as follows:
1. Two divs on a page cover the entire browser. Make sure that the left div is always 100px, and the right div changes with the size of the browser (for example, the browser is 500, and the right div is 400, the browser is 900, and the div on the right is 800), please write down the approximate css code.
1. Use flex
//html <div class='box'><div class='left'></div> <div class='right'></div></div> //css .box { width: 400px; height: 100px; display: flex; flex-direction: row; align-items: center; border: 1px solid #c3c3c3; } .left { flex-basis:100px; -webkit-flex-basis: 100px; /* Safari 6.1+ */ background-color: red; height: 100%; } .right { background-color: blue; flex-grow: 1; }
2. Floating layout
<div id="left">Left sidebar</div> <div id="content">Main Content</div> <style type="text/css"> * { margin: 0; padding: 0; } #left { float: left; width: 220px; background-color: green; } #content { background-color: orange; margin-left: 220px; /*==等于左边栏宽度==*/ } </style>
2. Please write down some front-end performance optimization methods, the better The more the better
1. Reduce DOM operations
2. Before deployment, image compression, code compression
3. Optimize js code Structure, reduce redundant code
4. Reduce http requests, set HTTP cache appropriately
5. Use content distribution cdn to accelerate
6. Static resource caching
7. Delayed loading of images
3. What happens in the process from inputting the URL to the completion of page loading and display of a page? (The more detailed the process, the better)
Enter the address
1. The browser searches for the IP address of the domain name
2.This One step includes the specific search process of DNS, including: browser cache->system cache->router cache...
3. The browser sends an HTTP request to the web server
4. Server Permanent redirect response (from http://example.com to http://www.example.com)
5. The browser tracks the redirect address
6. The server processes the request
7. The server returns an HTTP response
8. The browser displays HTML
9. The browser sends a request to obtain resources embedded in HTML (such as pictures, audio, Video, CSS, JS, etc.)
10. The browser sends an asynchronous request
4. Please briefly describe the restrictions on page access cookies
Cross-domain issues
Set HttpOnly
5. Describe browser redraw and reflow, What methods can improve the reflow caused by dom operations
1. Change the className directly. If you change the style dynamically, use cssText
// 不好的写法 var left = 1; var top = 1; el.style.left = left + "px"; el.style.top = top + "px"; // 比较好的写法 el.className += " className1"; // 比较好的写法 el.style.cssText += "; left: " + left + "px; top: " + top + "px;";
2. Let the elements to be operated be "offline processed" and update them together after processing
a) Use DocumentFragment to perform caching operations, triggering a reflow and Redraw;
b) Use display:none technology to trigger only two reflows and redraws;
c) Use cloneNode(true or false) and replaceChild technology to trigger one reflow and redraw Draw
Six, vue life cycle hook
##1. Cross domain through jsonp
2. Cross subdomain by modifying document.domain
3. Use window .name for cross-domain
4. Use the newly introduced window.postMessage method in HTML5 to transmit data across domains (ie 67 does not support it)
5. CORS requires the server to set the header: Access -Control-Allow-Origin.
6. This method of nginx reverse proxy is rarely mentioned, but it does not require the cooperation of the target server, but you need to build a transit nginx server to forward requests
8. Understanding of front-end engineering
Development specifications
Modular development
Component development
Component Warehouse
Performance Optimization
Project Deployment
Development Process
Development Tools
Nine, js deep copy method
1. Use jq’s $.extend(true, target, obj)
2. newobj = Object.create(sourceObj), // But there is a problem with this. Changes to newobj will not affect sourceobj, but changes to sourceobj will affect newObj
3.newobj = JSON.parse(JSON. stringify(sourceObj))
10. js design patterns
Generally speaking, design patterns are divided into three categories :
There are five creative patterns: factory method pattern,
Abstract factory pattern, singleton pattern, builder pattern, and prototype pattern. There are seven structural modes:
Adapter mode, Decorator mode, Agent mode, Appearance mode, Bridge mode, Combination mode, Flyweight mode. Behavioral patterns, eleven types in total: strategy pattern, template method pattern,
Observer pattern, iterative sub pattern, Chain of responsibility pattern, command pattern, memo Mode, state mode, visitor mode, mediator mode
11. Picture preview
<input type="file" name="file" onchange="showPreview(this)" /> <img id="portrait" src="" width="70" height="75"> function showPreview(source) { var file = source.files[0]; if(window.FileReader) { var fr = new FileReader(); fr.onloadend = function(e) { document.getElementById("portrait").src = e.target.result; }; fr.readAsDataURL(file); } }
##12 , Flattened multi-dimensional array
1, Old method
var result = [] function unfold(arr){ for(var i=0;i< arr.length;i++){ if(typeof arr[i]=="object" && arr[i].length>1) { unfold(arr[i]); } else { result.push(arr[i]); } } } var arr = [1,3,4,5,[6,[0,1,5],9],[2,5,[1,5]],[5]]; unfold(arr)
2、使用tostring
var c=[1,3,4,5,[6,[0,1,5],9],[2,5,[1,5]],[5]]; var b = c.toString().split(',')
3、使用es6的reduce函数
var arr=[1,3,4,5,[6,[0,1,5],9],[2,5,[1,5]],[5]]; const flatten = arr => arr.reduce((a, b) => a.concat(Array.isArray(b) ? flatten(b) : b), []); var result = flatten(arr)
十三、iframe有那些缺点?
iframe会阻塞主页面的Onload事件;
搜索引擎的检索程序无法解读这种页面,不利于SEO;
iframe和主页面共享连接池,而浏览器对相同域的连接有限制,所以会影响页面的并行加载。
使用iframe之前需要考虑这两个缺点。如果需要使用iframe,最好是通过javascript动态给iframe添加src属性值,这样可以绕开以上两个问题。
以上就是我收集的前端笔试题以及答案,所述对大家有所帮助。
推荐阅读:
The above is the detailed content of Summary of the latest front-end written test questions. For more information, please follow other related articles on the PHP Chinese website!