1.下面哪几个和 [http://store.company.com/dir/page.html](http://store.company.com/dir/page.html) 符合同源策略?( )
A、http://store.company.com/dir2/other.htm
B、https://store.company.com/dir/secure.html
C、http://store.company.com:81/dir/etc.html
D、http://news.company.com/dir/other.html
同源策略:同协议,同域名,同端口
同源策略:同协议,同域名,同端口
2.关于DOMContentLoaded和load事件说法正确的是?
A、DOMContentLoaded事件比load事件更早执行
B、load事件比DOMContentLoaded事件更早执行
C、按监听代码从上到下先后执行
D、dom文档完全加载完后执行load事件
- DOMContentLoaded
当纯HTML被完全加载以及解析时,DOMContentLoaded事件会被触发,而不必等待样式表,图片或者子框架完成加载。- Load
当一个资源及其依赖资源已完成加载时,将触发load事件
3.如何在 div 容器里展示 <div></div> 这几个字符?
A、<div><div></div></div>
B、<div>"<div></div>"</div>
C、document.querySelector('div').innerText = "<div></div>"
D、document.querySelector('div').innerHTML = "<div>sssssss</div>"
innerHTML:设置或获取标签所包含的HTML与文本信息。(不含标签本身)
innerText:设置或获取标签所包含的文本信息。(不含标签本身)
outerHTML:设置或获取标签本身以及所包含的HTML与文本信息。(包含标签本身)
outerText:设置或获取标签本身以及所包含的文本信息。(包含标签本身)
例如:
<div id="div1">
<p id="p1">this is text</p>
</div>
<script>
var div=document.getElementsByTagName("div");
console.log(div[0].innerHTML); // <p id="p1">this is text</p>
console.log(div[0].innerText); // this is text
console.log(div[0].outerHTML); // <div id="div1"><p id="p1">this is text</p></div>
console.log(div[0].outerText); // this is text
</script>
4.以下是哪一组全是块级元素?
A、div i h2 li
B、div p h1 ul
C、li ul h3 span
D、p h4 canvas em
5.<div class="box box1 box2" style="color:#222">hello</div>,
这个div里面最终的字体颜色是什么?
.box{
color:#999;
}
.box{
color:#333 !important;
}
.box2{
color:#666
}
A、#999
B、#222
C、#333
D、#666
6.以下不是box-sizing的属性是?
A、border-box
B、auto
C、content-box
D、inherit
7.以下不是CSS伪类选择器的是?
A、:first-child()
B、:before
C、:center
D、:after
8.‘-1 >>> 32 的值为( )’
A、-1
B、1
C、0
D、2^32-1
符号 功能 补位 >> 有符号右移 正补0,负补1 >>> 无符号右移 正负皆补0,且结果必为正数
MDN文档介绍说右操作数应小于32,而通过网上资料表明,不小于32时,实际的右移位数为d=d%32(d为右操作数),故可得本例子实际右移位数32%32=0,相当于没有移动
负数的二进制为正数的二进制取反加1
10进制 2进制 1 0000 0000 0000 0000 0000 0000 0000 0001 -1 1111 1111 1111 1111 1111 1111 1111 1111 由序号1说明-1没有移动,因此-1的二进制就是结果
为了便于表示,进行+1操作得:
1 0000 0000 0000 0000 0000 0000 0000 0000 -> 2^32
再进行-1得:2^32-1
所以最终选D
9.[1 < 2 < 3, 3 < 2 < 1] ( )
A、[true, true]
B、[true, false]
C、[false, true]
D、[false, false]
true为1,false为0
[1 < 2 < 3, 3 < 2 < 1]
[true < 3, false < 1]
[1 < 3, 0 < 1]
[true, true]
10.['1', '2', '3'].map(parseInt) ( )
A、[1, 2, 3]
B、[0, 1, 2]
C、[NaN, NaN, NaN]
D、[1, NaN, NaN]
['1','2','3'].map(parseInt)()相当于
['1','2','3'].map((item,index)=>{ return parseInt(item,index); })
parseInt('1',0)//1 默认十进制的1;
parseInt('2',1)//NaN 1进制没有2,
parseInt('3',2)雷同
11.let a = { c:1 }
let b = a
a = 1
b.c = 2
a.c = (?)
A、1
B、2
C、undefined
D、NaN
let a = { c:1 } //a的作用域指向 {c:1} 这个地址
let b = a //b的作用域指向 {c:1} 这个地址
a = 1 // a指向的作用域发生改变,指向1,但是{c:1} 这个地址还存在
b.c = 2 //改变{c:1} 这个地址中c的值为2a.c = (?) //a指向的地址已经发生改变,没有c这个变量,所以返回undefined
12.console.log(1);
setTimeout(() => {console.log(2)}, 0);
console.log(3);
Promise.resolve(4).then(b => {
console.log(b);
});
console.log(5);
A、1 2 3 4 5
B、1 3 5 4 2
C、1 4 2 3 5
D、1 3 5 2 4
console.log() -> 同步
promise -> 异步,微任务
setTimeout -> 异步,宏任务
执行顺序: 同步 > 异步,微任务 > 异步,宏任务
13.Math.abs(-6.666) 的结果是多少?
A、-6.666
B、6
C、-6
D、6.666
14.替换字符串 bilibili 替换字符串中所有的b变成大写B
A、'bilibili'.delete('b', 'B')
B、'bilibili'.replace(/b/g, 'B')
C、'bilibili'.replace('b', 'B')
D、'bilibili'.toUpperCase()
15.[1,2,3,4,5] 的数组的基础上 删除第一个 和 最后一位
A、[1,2,3,4,5].replace(1, -1)
B、[1,2,3,4,5].reverse(1,-1)
C、[1,2,3,4,5].toString(-1,1)
D、[1,2,3,4,5].slice(1, -1)
16.
function setname(name){
this.name = name
}
setname.prototype.printName = function(){ console.log(this.name) }
let a = new setname("cc")
a.name = "dd"
a.__proto__.name = "ee"
a.__proto__.printName() // ?
a.printName() // ?
A、ee dd
B、cc dd
C、ee cc
D、ee Error
隐式的this绑定。this指向调用对象。简单来说就是看getName()前的. 。.前面的对象就是this指向的方向。
a.__proto__.printName() -> this指向a._proto_
a.printName() -> this指向a
17.
const players = [ {name: 'UZI', team: 'RNG', position: 'ADC'},
{name: 'theshy', team: 'IG', position: 'TOP'},
{name: 'Metoer', team: 'BLG', position: 'Jungle'},
{name: 'ADD', team: 'BLG', position: 'TOP'},
{name: 'Scout', team: 'EDG', position: 'Middle'},
{name: 'iBoy', team: 'EDG', position: 'ADC'},
{name: 'Baolan', team: 'IG', position: 'Support'},
{name: 'Xiaohu', team: 'RNG', position: 'Middle'}]
获取列表中战队名是BLG 位置上路的 选手对象?
A、players.filter(x=> x.position === 'TOP' && x.team === 'BLG')
B、players.get(position='TOP', team='BLG')
C、players.find(position='TOP', team='BLG')
D、players.findOne(position='TOP', team='BLG')
个人代码,仅供参考
var len=await readline()
var str=await readline()
var arr=str.split(' ')
var target=await readline()
var j=len-1,i=0, sum = (arr[i]-'' )+ (arr[j]-'')
while (i < j && sum != target) {
if (sum < target) {
i++;
} else {
j--;
}
sum = (arr[i]-'' )+ (arr[j]-'');
}
if(i<j)
console.log(arr[i],arr[j])
else console.log("notfound")
个人代码,仅供参考:
var s=await readline()
var len= s.length
for (let i = 0; i < len; i++) {
s = s.replace('()', '')
s = s.replace('[]', '')
s = s.replace('{}', '')
}
if (s == '') {
console.log( true)
} else {
console.log( false)
}
个人代码,仅供参考:
var n=await readline()
var res=[]
res[1]=1,res[2]=2,res[3]=3
for(let i=4;i<=n;i++){
res[i]=res[i-1]+res[i-2]
}
console.log(res[n])
/* 到第n阶台阶只需要在n-1步台阶走一步或者n-2台阶走两步,
所以有多少种方法可以到n-1台阶就有多少种方法到n台阶,
有多少种方法到n-2台阶,就有多少种方法到n台阶,
所以dp[n]=dp[n-1]+dp[n-2] */