选择题
下面哪项的样式优先级最高
Answer (B)
A. div #span
B. #div .span
C. .div span
D. .div #span
下列说法正确的是
Answer (BC)
A. setTimeout(foo, 0) 这行代码可以等价替换为 foo()
B.使用 Object.assign() 可以实现对象的浅拷贝
C. for…in 循环只能遍历对象上的可枚举属性
D. Object.keys() 可以遍历出对象原型链上的属性
[‘1’, ‘2’, ‘3’].map(parseInt) 结果为?
Answer (D)
A. [1, 2, 3]
B. [0, 1, 2]
C. [NaN, NaN, NaN]
D. [1, NaN, NaN]
以下哪些场景下请求会触发跨域?
Answer(ABC)
A. 由 XMLHttpRequest 或 Fetch 发起的跨域 HTTP 请求
B. CSS 中通过 @font-face 使用字体资源
C. 使用 drawImage 将 Images/video 画面绘制到 canvas
D. html script 请求 JS 资源
下列说法正确的是
Answer(ACD)
A. requestAnimationFrame(foo) 确保使浏览器在下一次重绘之前调用 foo 方法
B. 在 addEventListener 的处理方法中使用 e.preventDefault() 可以阻止事件冒泡
C. 把
Coding
/**
- 使用 javascript 实现 parseUrl 方法
- @param {String}
- @returns {Object} 结构化的 URL 信息
- @example
- parseUrl(‘https://www.xiaohongshu.com/test?foo=true’) // return { origin: ‘https://www.xiaohongshu.com/test’, query: { foo: ‘true’ }}
- parseUrl(‘https://www.xiaohongshu.com/test?id=1&name=%E6%9D%A8#common’) // return { origin: ‘https://www.xiaohongshu.com/test’, query: { id: ‘1’, name: ‘杨’ }, hash: ‘common’ }
*/
Test Case
describe(‘test parseUrl’, () => {
const tests = [
{
input: ‘https://www.xiaohongshu.com/test?id=1&name=%E6%9D%A8#common’,
output: {
origin: ‘https://www.xiaohongshu.com/test’,
query: { id: ‘1’, name: ‘杨’ },
hash: ‘common’,
},
},
{
input: ‘https://www.xiaohongshu.com/test?foo=true’,
output: {
origin: ‘https://www.xiaohongshu.com/test’,
query: { foo: ‘true’ },
},
},
]
tests.forEach(test => {
it(test ${test.input}
, () => expect(parseUrl(test.input)).to.be.deep.equal(test.output))
})
})
validBrackets
/**
- 验证括号是否成功匹配
- @description 给定一个只包含 ‘(’,’)’,’[’,’]’,’{’,’}’ 的字符串(支持嵌套),判断是否按相同类型的括号和顺序进行闭合
- @param {String} input 原始字符串
- @returns {Boolean} 返回是否符合匹配规则
- @example
- validBrackets(’()’) // true
- validBrackets(’()[]{}’) // true
- validBrackets(’([{}])’) // true
- validBrackets(’(]’) // false
- validBrackets(’([)]’) // false
*/
Test Case
const tests = [
{ input: ‘()’, output: true },
{ input: ‘(){}[]’, output: true },
{ input: ‘({[]})’, output: true },
{ input: ‘(]’, output: false },
{ input: ‘([)]’, output: false },
]
describe(‘test validBrackets’, () => {
tests.forEach(test => {
it(test ${test.input}
, () => expect(solution(test.input)).to.be.equal(test.output))
})
})