Front-end basic interview questions 30 questions-1
-
-
- 1. What values can be taken by position in css and what is the difference
- 2. How to understand semantics
- 3. What are the data types in JavaScript
- 4. Explain event capture and event bubbling
- 5. What are the commonly used array methods, list at least 5 methods and their functions
- 6. What is the difference between v-if and v-show instructions in Vue
- 7. What is the difference between v-text and v-html in Vue, and what are the characteristics of { { }} syntax
- 8. Introduce MVVM
- 9. Please talk about your understanding of the box model
- 10. What are the results obtained by using the typeof operator in JavaScript?
- 11. Please list at least 5 commonly used string methods and explain their functions
- 12. Why should the data in the Vue component be a function
- 13. What is the principle of Vue2.x two-way binding
- 14. What are the CSS selectors and what are their priorities
- 15. What are the ways to judge whether an expression is an array
- 16. Can v-if and v-for be used together? If yes, please introduce the priority. If not, please explain the reason
- 17. What does Vue.nextTick() do?
- 18. What are the ways to achieve centering in CSS, write at least three
- 19. How to prevent event bubbling and default behavior, write standard methods
- 20. What are the lifecycle hooks of Vue components?
- 21. The difference between link and @import when introducing CSS
- 22. The function and difference of call and apply in JavaScript
- 23. What are the states of Promise and what do they mean?
- 24. What routing modes does VueRouter use
- 25. What methods can be called by VueRouter to implement programmatic navigation
- 26. Write a recursive function to realize the operation of factorial of a certain number, such as: 5! = 5 * 4 * 3 * 2 * 1
- 27. What is the function of filter in Vue2.x, and how to define it?
- 28. How does VueRouter implement route lazy loading
- 29. The difference between em and rem
- 30. How to implement deduplication of array elements, please write three methods to achieve
-
1. What values can be taken by position in css and what is the difference
static(默认值):默认值,没有定位
relative(相对定位):相对于自身的位置进行定位
absolute(绝对定位):相对于有定位属性的父元素进行定位
fixed(固定定位):相对于浏览器窗口进行定位
sticky(黏性定位):在没有到达指定位置时没有定位,到达位置后就会变成固定模式
2. How to understand semantics
易读性和维护性更好
SEO成分会更好,蜘蛛抓取更好
3. What are the data types in JavaScript
基本数据类型:string、number、boolean、undefined、null、symbol、biginit
引用类型:object
4. Explain event capture and event bubbling
事件冒泡:事件冒泡就是在一个对象上绑定事件,如果定义了事件的处理程序,就会调用处理程序。相反没有定义的话,这个事件会向对象的父级传播,知道事件被执行,最后到达最外层document对象上。
事件捕获:和事件冒泡是一个相反的过程,首先在document上找,有事件得到话就执行,没有一直往里面找,一直到到所点击的对象上的事件
5. What are the commonly used array methods, list at least 5 methods and their functions
foreach:遍历数值,没有返回值
map:遍历数组中,有返回值
some:遍历数组中,只要有一个满足条件就返回true
every:只有当全部满足条件的时候才返回true
splice:可以用来截取、替换、删除数组中的元素
6. What is the difference between v-if and v-show instructions in Vue
v-if是直接控制DOM是否渲染,v-show是通过控制css样式是否显示,在经常需要显示隐藏的时候时候v-show
7. What is the difference between v-text and v-html in Vue, and what are the characteristics of { { }} syntax
v-text不能解析html标签,v-html能解析标签,
{
{}}语法特点:拼接
算术运算
三元运算
能在控制台打印都能写在里面
8. Introduce MVVM
M:模型
V:视图
VM:视图模型
9. Please talk about your understanding of the box model
我们把盒模型分为了标准盒模型和怪异盒模型,其中标准盒模型的宽高就等于内容的宽高,而怪异盒模型的宽高包含了padding和border
10. What are the results obtained by using the typeof operator in JavaScript?
number string boolean object function
11. Please list at least 5 commonly used string methods and explain their functions
length:获取字符串的长度、
chartAt():返回指定位置的字符
indexOf():查找某个字符,有则返回第一次匹配到的位置,否则返回-1
lastindexOf():查找某个字符,有则返回最后一次匹配到的位置,否则返回-1
12. Why should the data in the Vue component be a function
因为组件data中的数据都应该是相互隔离的,应该私有化,如果写成对象形式的话引用,在多个组件使用时可能会发送错误
13. What is the principle of Vue2.x two-way binding
object.definpropoty
14. What are the CSS selectors and what are their priorities
类选择器
ID选择器
通配符
属性选择器
子选择器
后代选择器
标签选择器
伪类选择器
id选择器>类选择器>标签选择器>子选择器>后代选择器>伪类选择器
15. What are the ways to judge whether an expression is an array
- Array.prototype.isPrototypeOf(obj)
- obj instanceof Array
- Object.prototypr.toString.call(obj)
- Array.isArray()
16. Can v-if and v-for be used together? If yes, please introduce the priority. If not, please explain the reason
不应该一起使用,影响性能
如果要用的话,在vue2.x中,v-for优先v-if
在vue3.x中,v-if优先v-for
17. What does Vue.nextTick() do?
在下次 DOM 更新循环结束之后执行延迟回调。在修改数据之后立即使用这个方法,获取更新后的 DOM。
18. What are the ways to achieve centering in CSS, write at least three
- flex
- Absolute positioning + margin
- Absolute positioning + transform
19. How to prevent event bubbling and default behavior, write standard methods
-
prevent event bubbling
event.stopPropagation() addEventListener的第三个参数为true
-
prevent default behavior
1. event.preventDefault() 2. return fasle 3. returnValue=false (IE)
20. What are the lifecycle hooks of Vue components?
beforCreate
created
beformountd
mounted
beforupdate
updated
befordestory
destoryed
21. The difference between link and @import when introducing CSS
link会在dom渲染前加载,@import是在dom渲染完才加载
22. The function and difference of call and apply in JavaScript
作用:改变this指向
区别:call和apply的第一个参数是指向的对象,call在第一个参数后面可以跟n个参数,而apply在第一个参数后面只有一个数组参数
23. What are the states of Promise and what do they mean?
pending:正在进行中
rejected:失败
fulfilled:成功
24. What routing modes does VueRouter use
hash:使用url的hash值来作为路由。支持所有浏览器
history:使用HTML5 API和HTTP服务器端配置,没有后台配置的话,页面刷新时会出现404
25. What methods can be called by VueRouter to implement programmatic navigation
push():有历史记录,可以回退到上一次记录
replace():替换了记录,想当于没有历史记录,不可以回退到上一次
goBack():后退到上一次的历史记录
goForword():前进到下一次的历史记录
go():为-1时后退,可以回退或者前进很多层
26. Write a recursive function to realize the operation of factorial of a certain number, such as: 5! = 5 * 4 * 3 * 2 * 1
function fn(n){
if(n==1){
return 1
}
return n*fn(n-1)
}
fn(5)
27. What is the function of filter in Vue2.x, and how to define it?
用来过滤,一般可以用来格式化事件和金额,
全局过滤器定义:Vue.filter('过滤器的名字',function(val){
处理函数
})
局部过滤器定义:在filters选项中定义
28. How does VueRouter implement route lazy loading
ES6方法:()=>import('路径')
Vue异步加载技术:resolve=>require(['路径'],resolve)
29. The difference between em and rem
em相对于父元素字体大小
rem相对于根元素字体大小
30. How to implement deduplication of array elements, please write three methods to achieve
-
set
const res=Array.from(new Set(arr))
-
Using double-layer loop + splice method
function res(arr){ let len=arr.length for(let i=0;i<len;i++){ for(let j=i+1;j<len;j++){ if(arr[i]===arr[j]){ arr.splice(j,1) len-- j-- } } } return arr } res(arr)
-
Use the indexOf method of the array
function removeDuplicate(arr){ const newArr=[] arr.forEach(item=>{ if(newArr.indexOf(item)=== -1){ newArr.push(item) } }) return newArr } removeDuplicate()