-
字符串翻转
let str = 'hello'// ['h','e','l','l','o']// 先转换成数组,然后翻转,然后变回字符串 console.log(str.split('').reverse().join(''));
-
变量提升
var只提升变量名,function会整体提升
如果变量名和函数重名了,函数优先级更高一点
console.log(abc);//打印的是函数体,因为函数优先级更高function abc () { }var abc = 1234 -
for..in/for..of的区别
for in:一般用来遍历对象
for of :一般用来遍历可迭代的数据结构,比如数组(array) arugments,nodeList,字符串(string)集合(set)
-
如何中断for
break 中止
continue 跳过当前这一次循环
return 如果for循环在函数体中,也可以通过return中止
-
forEach如何中断
forEach中用return是没办法中断的,只能通过抛出异常的方法