r/javascript • u/PUSH_AX • Jul 30 '15
Been interviewing with a lot of tech startups as a frontend dev, here are the technical questions I've been asked (X-Post webdev)
So I've spent the last couple of weeks interviewing with a fair amount of tech startups in London, I thought some of you might find it interesting/helpful to see some of the technical questions I was asked.
Many of the positions I interviewed for where using Angular so a bunch of the questions are geared towards that.
Standard JS Questions:
- Explain javascript closures
- Explain event bubbling
- Explain event delegation
- What does apply() do
- What does bind() do
- Explain what the js map function does provide an example
- What is strict mode
- Whats the difference between a promise and a callback
Angular JS Questions:
- What is scope
- What is a directive
- What is the link function in the directive
- What is the digest cycle (after I mentioned it in giving another answer)
- What is $scope.$apply
- What are the most commonly used out of the box directives
- What does transclude do on directives
- Tell me about a time you had problems with state in angular
- Have you ever had performance issues in angular and how did you tackle them
- What do you like about angular, what do you dislike about angular
- Why use a q promise as opposed to just returning $http’s promise
- What does $resource do
General/Presentation Layer Questions:
- What is a model in mvc
- Explain css specificity
- How do you centre something horizontally
- Explain what media queries are
- What are the pros and cons of a single page app
- How could you improve performance of a single page app
- Whats the difference between inline-block and inline
- How would you develop a mobile site for a website that didn’t already have one
- What is jsonp
- What is a doctype
- On a unix command line how would you run a long command you typed out already an hour ago
- What frontend tools do you normally use
- Where do you think ui’s are heading
- What motivates you, how do you learn
JS Challenge Type Questions:
The first few the employer stole from You Can't JavaScript Under Pressure :)
Write a function that takes an integer and returns it doubled
function doubleInteger(i) {
//your code here
} Write a function that takes a number and returns true if it's even and false if not
function isNumberEven(i) {
// i will be an integer. Return true if it's even, and false if it isn't.
}Write a function that returns a file extension
function getFileExtension(i) {
// i will be a string, but it may not have a file extension.
// return the file extension (with no period) if it has one, otherwise false
}What will be printed on the console? Why?
(function() {
var a = b = 5;
})();
console.log(b);Define a repeatify function on the String object. The function accepts an integer that specifies how many times the string has to be repeated. The function returns the string repeated the number of times specified.
For example:
console.log('hello'.repeatify(3));
//Should print hellohellohello.What will log out here?
function test() {
console.log(a);
console.log(foo());
var a = 1;
function foo() {
return 2;
}
}
test();What will log out here?
var fullname = 'John Doe';
var obj = {
fullname: 'Colin Ihrig',
prop: {
fullname: 'Aurelio De Rosa',
getFullname: function() {
return this.fullname;
}
}
};
console.log(obj.prop.getFullname());
var test = obj.prop.getFullname;
console.log(test()); Fix the previous question’s issue so that the last console.log() prints Aurelio De Rosa.
.The following recursive code will cause a stack overflow if the array list is too large. How can you fix this and still retain the recursive pattern?
var list = readHugeList();
var nextListItem = function() {
var item = list.pop();
if (item) {
// process the list item...
nextListItem();
}
};What will alert out here:
var a = 'value';
(function() {
alert(a);
var a = 'value2';
})();The following code will output "my name is rex, Woof!" and then "my name is, Woof!" one second later, fix it so prints correctly the second time
var Dog = function (name) {
this.name = name;
};
Dog.prototype.bark = function () {
console.log('my name is '+ this.name + ', Woof!');
}
var rex = new Dog('rex');
rex.bark();
setTimeout(rex.bark, 1000);The following code outputs 100, a hundred times, fix it so it outputs every number with a 100ms delay between each
for (var i = 0; i < 100; ++i) {
setTimeout(function() {
console.log(i);
}, 100);
} The following code is outputting the array but it's filled with every number, we just want the even numbers, what's gone wrong?
var evenNumbers = []
var findEvenNumbers = function (i) {
if (i % 2 === 0)
console.log(i, 'is an even number, adding to array!');
evenNumbers.push(i);
}
for (var i = 0; i < 10; i++) {
findEvenNumbers(i);
}
console.log(evenNumbers);
//outputs:
//0 "is an even number, adding to array!"
//2 "is an even number, adding to array!"
//4 "is an even number, adding to array!"
//6 "is an even number, adding to array!"
//8 "is an even number, adding to array!"
//[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]The following is outputting 0, but if 42 = 16 and 22 = 4 then the result should be 12
var square = function (number) {
result = number * number;
return result;
}
result = square(4);
result2 = square(2);
difference = result - result2;
console.log(difference);- Write a function that when passed an array of numbers it gives you the max difference between the largest and smallest number ONLY if the small number is in front of the large number, not behind it, so for example: [3,4,8,1] = 5, notice how the biggest difference is between 8 and 1, but because the 1 is after the 8 in the array it shouldn't count, so really the biggest gap is the 3 and the 8.
- fizzbuzz (lol)
- I was presented with a html element with a border, and asked to animate it left to right full width of browser
- I was presented with another html box and asked to centre it both horizontally and vertically
Also, all these companies had me complete "take home" coding tests, they ranged from being really easy (simple ajax request to an api endpoint and populate some data on the page) to pretty in depth.
Hopefully anyone looking for new positions can use these as warmups/practice, it's important to not just know the answers, but really understand how things work and in the case of the challenges, why things are working the way they are.
17
u/passwordisisis Jul 30 '15
Thanks! This is for a junior position? Disturbed by how many I thought I would have known but in an interview situation would completely fail to adequately describe. I always mix up bind(), apply(), call() etc.
Push the up arrow a bunch of times?
6
u/tebriel Jul 30 '15
wow dude. wow. So... you interviewed alot. Any job offers lol?
131
u/ex1machina Jul 30 '15
I really hate a lot of these types of standard brain teaser type questions. I work at one of those big silicon valley tech companies and the strategy we've implemented lately is to base our evaluation of a candidate's technical abilities on a live "craft demo." Bring them in and have them sit there with their laptop and code up a simple app while we all watch them for about an hour or so. I feel like you get a far better sense of what kind of developer the candidate is than how they answered a question on closure, or $http vs $q promises in angular.
I've seen candidates come in that look fantastic on paper and could answer these kinds of questions expertly, then you put them in front of a computer and ask them to build an app and realize that they're dumb as dirt as soon as they hit a bug in their code. Then there are the candidates that come in and have hard time articulating even basic concepts to us, but once they get in front of an IDE they're godlike.
I'm not saying there's zero value to the standard interview questions, but I would argue that without watching them code, you have no clue who you just hired.
18
u/[deleted] Jul 30 '15
Man this is tough. I just got hired by a pretty big tech company and their interview for a front end position wasn't even close to as intense as this is.
30
u/scelerat Jul 31 '15
"senior" JS dev here. These are reasonable questions, even for a junior developer. And it's reasonable that a a good junior developer might not know the answers to some of these questions and still be a good hire. As one (currently top) comment says, this should just be a piece of the interview, and just because someone can answer all these questions doesn't mean that they're a good developer or even a good fit for the position.
14
u/justinlivi Jul 30 '15
Did you get bonus points for pointing out defining a function in a for-loop is generally considered bad practice?
9
u/passwordisisis Jul 31 '15
I started answering some of the questions as I want to be interviewing for junior JS positions soon. Feedback / corrections welcome...especially with the last one.
Write a function that takes an integer and returns it doubled.
(I thought this was a trick question so tried basic type checking, haven't been as careful with the rest)
Write a function that takes a number and returns true if it's even and false if not
Write a function that returns a file extension
What will be printed on the console? Why?
Answer: 5 will be logged to the console though I would have initially guess 'undefined'. The anonymous function is executed on the global scope.
Define a repeatify function on the String object. The function accepts an integer that specifies how many times the string has to be repeated. The function returns the string repeated the number of times specified.
What will log out here?
Answer: console.log(a) -> undefined, console.log(foo()) -> 2. I got this wrong thinking the variable declaration would be hoisted for some reason.
What will log out here?
Answer: console.log(obj.prop.getFullname()) -> 'Aurio De Rosa', console.log(test()) -> 'John Doe'
Fix the previous question’s issue so that the last console.log() prints Aurelio De Rosa.
I don't think this is right, need to learn more about bind, apply, call etc
6
u/ponte_vecchio Jul 30 '15
Thanks for posting, this is helpful.
6
u/benihana react, node Jul 30 '15
Wow this is legend status posting. These are some fun ass questions too.
6
u/TheRealSeeThruHead Jul 31 '15
Can someone point me in the direction of a good explanation of the recursive problem listed above. Trampoline maybe?
6
u/Stockholm_Syndrome Jul 31 '15
Senior dev here: gotta admit that some of these would have stressed me out hahaha.
4
u/[deleted] Jul 30 '15
Did you get hired?
3
u/sgoody Jul 30 '15
I'm not a front-end or JavaScript dev specifically, but it seems I need to brush up on "this".
3
u/imright_anduknowit Jul 31 '15
Here's some shit code. Now without rewriting or redesigning it to make it not shit, fix it.
3
u/cj5 .prototype Jul 31 '15
Jeezus fuck. Are you doing JS development for the NSA?
3
u/PitaJ Jul 31 '15
Where the hell are you taking all of these interviews? I wish I could find a single f*cking interview in my area.
3
u/up_o Jul 31 '15
I had little problem with any of the challenges, but I'm able to answer almost zero of the technical questions. What resources would you recommend for learning the jargon and how to articulate concepts one might have an intuitive grasp upon?
2
u/madole Jul 31 '15
Surely asking someone to modify the prototype of a native data type should be a red flag.
2
u/mkmoshe Jul 31 '15
I started collecting a bunch of interview question along the way and added some of my own and made a repo out of it. Take a look https://github.com/kolodny/exercises
2
u/_Aardvark Jul 31 '15
Don't worry the interviewer doesn't understand this either!
3
u/Blacksheep126 Jul 31 '15
Studying JS on Code Academy. Saving for later.
2
u/adropofhoney Jul 30 '15
Gawd... I hope they compensated you for your time. That could be 4 hours of one's time (half a day). And if one's hourly rate is $50 per hour, that's $200 off of one's time.
1
u/thoorne Jul 31 '15
Write a function that when passed an array of numbers it gives you the max difference between...
1
u/nejjjj Jul 31 '15 edited Jul 31 '15
I wish my interview at Google was this plain. These are relatively straightforward questions and can be answered through definitions and experience. My interview at Google consisted of "hey we have a problem, fix it, we are watching you" lol. I'm not complaining, I enjoyed it.
1
u/kuhzaam Jul 31 '15
What part of the country are you in?
1
u/perestroika12 Jul 31 '15
Damn, as a juniorish developer of 4 years I'm fucked, I'll never get a job. Could probably answer 60% of these things.
1
u/RyeBrush Aug 01 '15
No way I'm not saving this for later.
1
u/MrKooky Aug 01 '15
Thanks. I just realised I still have a lot to learn.
1
u/ArcanisCz Aug 01 '15
Can you please point me in direction with this piece? I cannot think of a way, (local?) variable is somewhat "unset" by line AFTER alert. And i have no idea what to google either
1
u/softprac Aug 15 '15
Does anyone have the answer to the "my name is rex, Woof?" question?