The other day I found rather thorough quiz on css, html and js.One may consider it boring, nonetheless many interesting edge-cases are considered.The only problem I consider is that no explanations is given. Author promotes his book at the end of the quiz, but I decided to be a naughty person and provide explanation to all questions for free ;-) I’d suggest you to take the quiz again, skipping all questions and not answering last one.Take the quiz
FULL SPOILERS AHEAD!
margin-top
and margin-bottom
in CSS21: 8.3 Margin properties> These properties have no effect on non-replaced inline elements.
:checked
pseudo-class initially applies to such elements that have the HTML4 selected and checked attributes as described in Section 17.2.1 of HTML4
:root
pseudo-class represents an element that is the root of the document. In HTML 4, this is always the HTML element.:nth-of-type(odd)
is applicable here, hence rule with it is used:hover
has separate background-image, this image would not be loaded until actual hover happens.display:none
- test#2display:none
test#3 and not due to visibility:hidden
.highlight
element, though) and make sure that semantic of all but <mark>
tag don’t fit the situation.<a>
tags as block at html5doctorvisibility:hidden
preserves element in content flow and its sizes should be determined. For image element default size is obtained from its content, hence image should be loaded. Also see next point.display:none
element I can’t find direct statement, that images should be loaded, there’re some evidence for that, though: w3:img > In a browsing context where scripting is disabled, user agents may obtain images immediately or on demand. In a browsing context where scripting is enabled, user agents must obtain images immediately Also practical observations show, that image is loaded even when detached from DOM. This feature has been being used for js image preload for long time.If Type(lprim) is String or Type(rprim) is String, then > Return the String that is the result of concatenating ToString(lprim) followed by ToString(rprim) hence addition of number and string is a concatenation of two operands converted to strings
foo
and first line foo = 10;
actually overwrites local variable. Top-level name foo
is remained untouched and its initial value is alerted.
function bar() {
var foo = function () {}; // both declaration and initialization is hoisted
return foo;
foo = 10;
foo = 11; // re-declaration does nothing
}
Variable hoisting is really an important thing to understand. One more link to good article about hoisting.
go
become detached reference w/o any knowledge, whose method it was and this
become global for its calls. More formally go
is actually a reference variable in current scope. When function call is performed, according to 6b, _thisValue_
is taken from top-level scope: object environment record. Its ImplicitThisValuereturns undefined
, which is replaced with global object when entering function code BTW constructions like (1,foo.baz.bar)();
also leads to detached function reference.this
set to global context.x
is referred to primitive value from outer scope. According to es5#13.2.2 if return type is not an object, actual return value is as if no return was called.arguments
object always has list of actually passed arguments. It is foo.length
, what is equals to 1
. es5#10.6:arguments> args be the actual arguments passed to the [[Call]] internal method … > 1. Let len be the number of elements in args … > 7. Call the [[DefineOwnProperty]] internal method on obj passing “length”, the Property Descriptor {[[Value]]: len, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: true}, and false as arguments.bar
is only available within the function body: see note on es5#13:function definition.There is a bug in IE8-, though, when such names leaks into scope.JScript Deviations from ES3 2.7 Function Expressions: §11.2.5, p10.length
is affected only by assigning numerical-indexed properties. More on that in es5#15.4.5.1.Configurable
es5#8.6.1:attribute set to false and hence property could not be deleted.Wow, you made it so far. If you wonder, I got 79% on the first try.