I’m one of the people that wrote the technical test that my company uses when it recruits. I sometimes give the test, which involves leaving the candidate with it for half an hour then coming back and going over the answers. How well did they understand? Do they understand the reasoning behind the answers? If they don’t and I start explaining can they use the information to complete the question? Can we have interesting conversations comparing algorithms and the pros and cons of different design patterns? Or will we struggle to understand what the following means in Java?
public Polygon(){ this(5); }
Here are a couple of the kinds of question I set in the Javascript part of the test. The questions have subtleties, but these are the kinds of things our developers deal with every day. Many of us have lost time to the bugs here, and if you’re using this language in your job and you understand it then you’ll recognise what I’ve done.
What is the output of this?
function OrderedMap(){ this.list = []; return this; } OrderedMap.prototype = { map : {}, list : [], put : function(key, value){ this.map[key] = value; this.list.push(value); }, get : function(key){ return this.map[key]; }, getAtIndex : function(index){ return this.list[index]; } } var test1 = new OrderedMap(), test2 = new OrderedMap(); test1.put(1, 'Fred'); test2.put(1, 'Joe'); console.log(test1.get(1)); console.log(test1.getAtIndex(0)); console.log(test2.get(1)); console.log(test2.getAtIndex(0));
What happens when you click the third button? Why? How would you change it?
(function(){ var body = document.body, i, button; for(i = 1; i <= 5; i++){ button = document.createElement('Button'); button.addEventListener('click', function(){ alert("I'm button " + i); }); button.appendChild(document.createTextNode('Button ' + i)); body.appendChild(button); } }());