FrontTuesday Trivia: Part 2

FrontTuesday Trivia: Part 2

For the latest gathering, we started with a short presentation by Maria Comas regarding styled blocks with scoped attributes and then proceeded to jump into the quiz right where we had left off. The first couple of questions were relatively easy to answer. For example, we all knew that if a block is hidden with the “display” property, it will not appear on the page at all and that it causes a DOM reflow, unlike the “visibility property”.

However, both of them can cause HTTP requests when the page loads when applied to an image tag. Other questions in this section consisted of DOM parsing and code execution, which we found very intriguing.

Everyone was getting excited about the main part of the gathering - the JavaScript section. So, with the tension rising and everyone ready to go, we pressed the start button!

We were not fooled by the first question and everyone recalled the awesome lightning talk given by Gary Bernhardt at CodeMash in 2012. I believe the sarcasm he used to visualize some of the potential pitfalls in JavaScript, stuck in everyone’s minds, and has been a great reference point when dealing with the technology.

The question was along these lines: “What does the following statement evaluate to: “1” + 2 + “3” + 4?  - The answer was plain and simple - 1234. The thing is that when you add a number and a string in Javascript the result is always a string. But if we write the statement as 4 + 3 + 2 + “1”, it evaluates to 91. If we’d like to get 10 as a result, we would need to use a so-called unary plus sign here, like this: 4 + 3 + 2 + +“1” or use parseInt(): 4 + 3 + 2 + parseInt(“1”).

We found the following example pretty interesting:

var foo = function bar() {};
alert(typeof bar);

We are assigning the bar function to a foo variable. This will alert “undefined” because the function is not globally defined, but lives as a variable. Which we got right!

We could tell that we were on the right track when we stumbled on some crazy examples that brought about some good discussions, like this one for example:

var foo = 1;
function bar() {
  foo = 10;
  function foo() {}

What is alerted in the example above? (The answer is 1).

I still remember somebody commenting “Who writes code like this?!” While another replied: “Nobody here, that’s for sure!” :)

This time around our score was 17/25, which is understandable, as some of the examples were quite tricky. We aim to take a different approach at the next FrontTuesday and will try to create our own Trivia night with different kinds of questions. We’re super excited and look forward to learning more while still having fun!

Other blogs in this series:


Let us know how we can help you.