前端小学生向大家推荐一个网站:Sit the test。如果你是一名前端工程师或者立志于此,不妨试试此网站上面的测验题。

发现

  十几天前,我在奇舞周刊的一篇文章中,发现了一个国外的技能测试网站:Sit the test。测试分为HTML CoreCSS CoreCSS Core(practice)JavaScript Core四部分,每种测试有25道题,限时30分钟。有了国内大牛的博客推荐,让我对测试题的含金量十分信服,当时我迫于证明自己,马上抽出时间挨着做了一遍:

  做完就傻眼了,25题错7道,好像拿捏不准的全错了。题确确实实只是基础题,但是我没仔细看过W3C Standers,凭项目经验以及看过一些进阶书籍硬是把“基础送分题”变成了“附加题”。

分享

  让人比较郁闷的是,除了CSS Core(practice),其它三个测试只给出正确率,具体哪道做错了根本不告诉你,更别说正确答案应该是什么了。并且一个星期内只能参加一次测验,真是神奇极了。熟知测试规则后,我把自己做的题全都截图保存了下来,抽空仔细推敲了一遍。下面我抛砖引玉,将一些确定做错的题拿出来分享给大家。(答案放在最后,我无法将所有题的答案分享出来,因为最近我又进行了一遍测试,发现原题,题的顺序以及选项的顺序都会变)

  1. Which of the following CSS measurements is the smallest in terms of physical size on a typical desktop display? Assume only default browser styles are in effect.

    A:1ex  B:1px  C:1pt  D:1em

  2. Your site’s stylesheet contains two rules with exactly the same selector. Which of the following statements correctly describes how this code will apply to a web page?

    A:Both rules apply to all matching elements, with the second rule overriding the first.

    B:The second rule takes precedence, and the browser ignores the first.

  3. Which of the following CSS color codes denotes a color that contains twice as much red as it does blue?

    A:#7F0BFE  B:#102005  C:#AACC55  D:#221144

  4. When you specify a percentage value for margin-top on an element, how is this margin’s actual size calculated?

    A:As a percentage of the width of the containing block.

    B:As a percentage of the height of the containing block.

  5. In a CSS color code such as #f06523.what does it mean if the code is composed of three identical pairs of digits(i.e. #XYXYXY)?

    A:the color code will have the same brightness if inverted.

    B:the color code represents a web-safe color.

    C:the color code represents a shade of gray.

    D:the color code has a complementary color with the digits inverted.

  6. which of the following best describes the difference between event handlers and event listeners?

    A:Event handler are embedded in HTML attributes;the other are assigned in JavaScript code.

    B:Event handlers are a nonstandard,proprietarty browser feature;the other are standards-compliant.

    C:For a given event type,an element may only have one event handler,but may have multiple event listeners.

    D:IE supports event handlers;other browsers support event listeners.

  7. Your Web page loads JavaScript code that is run using each of the following techniques:

    ①:DOMContentLoaded event listener      ②:load event listener

    ③:<script> tag immediately before </body>  ④:<script> tag in the document's head

    In what order will each of these scripts be executed?

    A:3,4,1,2  B:2,3,4,1  C:4,3,1,2  D:2,4,3,1

  8. You wish to display text on your website with double-spaced lines by default.Which of the following line-height values is the best way to achieve this?

    A:inherit  B:200%  C:2em  D:2

  解析:

  1. 选B。em和ex是相对单位,em具体大小根据相关元素的“font-size”得出,而ex的具体大小根据相关字体的“x-height”得出。“x-height”往往等于相关字体中小写字母"x"的高度。px和pt是绝对单位,在CSS中,1pt=1英寸的七十二分之一,而1px=0.75pt。在低分辨率设备中(例如电脑显示器),1px*1px覆盖了设备的一个点,故此选B,1px。

  2. 选A。两个一模一样的CSS规则应用在页面上,效果我们都知道,但原理要搞清楚:浏览器并非是忽略掉了第一个声明,而是两个声明都会生效,后者覆盖掉了前者。

  3. 选C。RGB颜色可以使用16进制来表示。rgb(255,0,0)=#f00=#ff0000=rgb(100%, 0%, 0%);#AACC55转换为rgb表示为rgb(170,204,85),170=85*2,红色是蓝色的两倍。

  4. 选A。W3C标准中指出:“The percentage is calculated with respect to the width of the generated box's containing block”,并特别强调:“Note that this is true for 'margin-top' and 'margin-bottom' as well”。

  5. 选C。又是RGB,首先必须明确一个事实,黑白之间的颜色叫灰色,不管它多接近于黑,也不管它多接近于白。当R,G,B三个通道数值一样时,这个颜色的饱和度就为0,代表了黑与白之间的颜色。这个可能是计算机图形学的基础知识。

  6. 选C。StackOverflow上关于Event handlers vs event listeners的问题有很多,但是都没有给出参考引用,让人不信服。直到我在MDN中看到这句话:

  When discussing the various methods of listening to events,

  • event listener refers to a function or object registered via EventTarget.addEventListener(),
  • whereas event handler refers to a function registered via on... attributes or properties.

  搞清楚定义后,MDN又回答了"Why use addEventListener?":

  addEventListener is the way to register an event listener as specified in W3C DOM. Its benefits are as follows:

  1. It allows adding more than a single handler for an event. This is particularly useful for DHTML libraries or Mozilla extensions that need to work well even if other libraries/extensions are used.
  2. It gives you finer-grained control of the phase when the listener gets activated (capturing vs. bubbling)
  3. It works on any DOM element, not just HTML elements.

  至此,答案已经很明显了。可能还有人会质疑选项B为什么不对。B选项说“on...”这种方式是非标准的浏览器专属特性,而addEventListener是W3C标准API。后半句毋庸置疑,addEventListener是在DOM Level2中引进的。而Event Handlers是在DOM0出现的。参考Cross-Browser.com上的一句话:

  “There is no formal DOM0 standard. By "DOM0" we are referring to the object model supported by both IE4 and NN4. The DOM0 event interface is still supported by modern browsers.”

  并没有DOM0标准,仅仅是把它当作W3C DOM1之前“民间标准”的统称。这时候B好像是正确的,但是很遗憾,在W3C HTML5的标准文档中,对Event Handlers进行了规范化定义。HTML5 The definition of 'event handlers' in that specification。

  至此,本题的疑问已经全部解决。(我对选项B解释的合理性不是很确定,如果你有更好的解释,请在评论中指出)

  7. 选C。首先必须弄清楚DOMContentLoaded和load的区别。请看StackOverflow上的回答,以及Demo。搞清楚这两个的区别之后,可以写一段代码来验证。

<!Doctype html>
<html>
<head>
<title>Test</title>
<script type="text/javascript">
window.addEventListener("load", function(event) {
console.log("2");//load event listener
});
document.addEventListener("DOMContentLoaded", function(event) {
console.log("1");//DOMContentLoaded event listener IE9+等现代浏览器支持
});
console.info("4");//<script> tag in the document's head
</script>
</head>
<body>
<script type="text/javascript">
console.info("3");//<script> tag immediately before </body>
</script>
</body>
</html>

  打印的顺序正是4,3,1,2。

  8. 选D。<number> and <percentage>方式设定的line-height值的计算方式都是(value*font-size),也就是说,假使段落字体为14px,那么line-height:200%和line-height:2计算出的结果都是line-height:28px。W3C标准指出,line-height的默认值为“normal”,建议浏览器将此值默认在1.0~1.2之间,并且强调“The value has the same meaning as <number>”。在对<number>的解释中,又特别强调了“The computed value is the same as the specified value”。这在对<percentage>的解释中都是没有的。其实这么书面化的标准对应到浏览器的表现形式上就是,<number>形式的值可以被后代继承,而<percentage>则不能,后代只会继承父亲的计算值。为了防止因为line-height继承导致的文字重叠,应使用<number>。因此D选项,“2”是设置双倍行距的最佳值。

总结

  假如一个精读过W3C Standers的人来做这套测试题,准确率绝对不会低于90%。而我本人在找实习的过程中,比较大型的互联网企业基本都在关心实习生对前端技能中Core部分的掌握,以及数据结构与算法等计算机基础知识。我一直觉得自己对CSS的使用和认知是精于JavaScript的,但是测试结果确实出乎我的意料。看来CSS边边角角的知识比JavaScript要多一些,而这些知识正是我目前所欠缺的。没有拿到80%以上成绩的小伙伴,和我一起抽出时间认认真真阅读和理解一下W3C标准文档吧。

  最后,用我的导师说过的一句话来总结全文:基础不牢,地动山摇。

  望诸君共勉。

  (完)

检验你的前端基础——Sit the test的更多相关文章

  1. web前端基础知识及快速入门指南

    web前端基础知识及快速入门指南 做前端开发有几个月了,虽然说是几个月,但是中间断断续续的上课.考试以及其它杂七杂八的事情,到现在居然一直感觉自己虽然很多前端的知识很眼熟,却也感觉自己貌似也知识在门口 ...

  2. html css 前端基础 学习方法及经验分享

    前言: 入园第一天,想分享一点儿前端基础html css 的学习方法和一些经验给热爱前端,但是不知道从哪儿开始,依旧有些迷茫的新手朋友们.当然,适合每个人的学习方式不同,以下所讲的仅供参考. 一.关于 ...

  3. HTML+DIV+CSS+JSweb前端基础

    HTML+DIV+CSS+JSweb前端基础 1.<html>和</html> 标签限定了文档的开始和结束点. 属性: (1)  dir: 文本的显示方向,默认是从左向右 (2 ...

  4. 前端基础面试题(JS部分)

    1.几种基本数据类型?复杂数据类型?值类型和引用数据类型?堆栈数据结构? 基本数据类型:Undefined.Null.Boolean.Number.String 值类型:数值.布尔值.null.und ...

  5. 前端基础之DOM和BOM

    前端基础之DOM和BOM JavaScript分为 ECMAScript,DOM,BOM. BOM(Browser Object Model)是指浏览器对象模型,它使 JavaScript 有能力与浏 ...

  6. tableview前端基础设计(初级版)

    tableView前端基础设计 实现的最终效果 操作目的:熟悉纯代码编辑TableView和常用的相关控件SearchBar.NavigationBar.TabBar等,以及布局和基本功能的实现. 一 ...

  7. web前端基础学习路线

    1.HTML和CSS的基础知识,完成网页的初步设计 2.JavaScript基础知识和DOM.BOM的学习 3.前端基础框架:CSS框架Bootstrap.JavaScript框架jquery的熟悉使 ...

  8. JS BOM DOM对象 select联动 计时器 时间 css操作 节点(标签 ) 查找标签 {前端基础之BOM和DOM}

    前端基础之BOM和DOM 前戏 到目前为止,我们已经学过了JavaScript的一些简单的语法.但是这些简单的语法,并没有和浏览器有任何交互. 也就是我们还不能制作一些我们经常看到的网页的一些交互,我 ...

  9. 前端基础进阶(五):全方位解读this

    https://segmentfault.com/a/1190000012646488  https://yangbo5207.github.io/wutongluo/ 说明:此处只是记录阅读前端基础 ...

随机推荐

  1. Shell替换

    如果表达式中包含特殊字符,Shell 将会进行替换.例如,在双引号中使用变量就是一种替换,转义字符也是一种替换. #!/bin/bash a= echo -e "Value of a is ...

  2. Cassandra简介

    在前面的一篇文章<图形数据库Neo4J简介>中,我们介绍了一种非常流行的图形数据库Neo4J的使用方法.而在本文中,我们将对另外一种类型的NoSQL数据库——Cassandra进行简单地介 ...

  3. JavaScript动画-碰撞检测

    ▓▓▓▓▓▓ 大致介绍 碰撞检测是指在页面中有多个元素时,拖拽一个元素会出现碰撞问题,碰撞检测是以模拟拖拽和磁性吸附中的范围限定为基础的 效果:碰撞检测 ▓▓▓▓▓▓ 碰撞检测 先来看看碰撞检测的原理 ...

  4. Angular2开发笔记

    Problem 使用依赖注入应该注意些什么 服务一般用来做什么 指令一般用来做什么 angular2如何提取公共组件 angular2为什么不需要提公共组件 父组件与子组件之间如何通讯 什么时候应该使 ...

  5. angularjs 依赖注入--自己学着实现

    在用angular依赖注入时,感觉很好用,他的出现是 为了"削减计算机程序的耦合问题" ,我怀着敬畏与好奇的心情,轻轻的走进了angular源码,看看他到底是怎么实现的,我也想写个 ...

  6. [C#] C# 知识回顾 - 特性 Attribute

    C# 知识回顾 - 特性 Attribute [博主]反骨仔 [原文地址]http://www.cnblogs.com/liqingwen/p/5911289.html 目录 特性简介 使用特性 特性 ...

  7. await and async

    Most people have already heard about the new “async” and “await” functionality coming in Visual Stud ...

  8. C# 数组的交集、差集、并集

    C# 数组的交集.差集.并集 工作中经常会用这方面的知识来检查那些字段是必须输入的,那些是禁止输入. using System; using System.Collections.Generic; u ...

  9. 微信小程序开发日记——高仿知乎日报(下)

    本人对知乎日报是情有独钟,看我的博客和github就知道了,写了几个不同技术类型的知乎日报APP 要做微信小程序首先要对html,css,js有一定的基础,还有对微信小程序的API也要非常熟悉 我将该 ...

  10. 整体二分QAQ

    POJ 2104 K-th Number 时空隧道 题意: 给出一个序列,每次查询区间第k小 分析: 整体二分入门题? 代码: #include<algorithm> #include&l ...