js基础面试

2017-10-05  本文已影响4人  西兰花伟大炮
(1)slice()与substring(start,stop)的区别

都用于提取字符串中介于两个指定下标之间的字符,substring()不接受下标为负数,如果参数 start 与 stop 相等,那么该方法返回的就是一个空串(即长度为 0 的字符串)。如果 start 比 stop 大,那么该方法在提取子串之前会先交换这两个参数,结果不包括stop

image.png

substring原则上不接受负数,当强行传入负数,则会当作0处理,并对传入的参数进行正序排列,再进行截取

image.png

不提倡使用substr( start, length),不是ECMAscript标准

(2)onfocus

onfocus 事件在对象获得焦点时发生。
Onfocus 通常用于 <input>, <select>, 和<a>


(4)lastIndexOf()
image.png
(5)在数组长度外进行赋值,会以赋值处长度作为数组长度,前面的全部填充为undefined
image.png
var arr =[1,2,3,4];
    arr[10] = 10;
    console.log(arr.length); //11
(6)为类数组对象设置样式,需要进行遍历或单独选中
image.png
(7)domReady

给还未解析到的dom元素绑定事件会报错,应该加上onload事件


image.png

html元素可以内联绑定多个事件


(8)confirm对话框
image.png
(9)清除浮动
image.png
(10)冒泡与捕获流程
image.png
image.png
(11)关于遍历数组找出匹配项进行操作
  • 直接进行for循环
  • Array.indexOf()
  • Array.forEach() 不能返回值
    Array.include(target)

image.png
(12)undefined,null转字符串
image.png
(13)数组map方法必须得有返回值
(14)判断是否是IE浏览器
image.png
上一篇 下一篇

猜你喜欢

热点阅读