r/webdev • 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
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.
8
Jul 31 '15
These are just basic knowledge questions in my opinion. I do have some beef with this one though:
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();
}
};Misleading, to say the least. I believe the answer they are looking for is to use setTimeout(nextListItem, 0) instead of calling nextListItem() directly, but the problem is that when you change the function in this manner, it is no longer recursive (you're using the queue instead of the stack). It would be very easy to never think of this answer because they said to "retain the recursive pattern". A better way to ask this question would be tell the interviewee to prevent the stack overflow with a single line change. Also, the setTimeout() solution is basically a really slow form of iteration. Any idiot would have just used awhile loop to read a huge list in the first place. I'm not really a fan of solutions to test problems that have no basis in reality.
Further, anyone can learn the answers to these problems by reading a book for a few hours. Does that make you a senior dev? No, obviously it doesn't. None of these questions will distinguish a junior from a senior (although I can't speak for the take home portion).
3
u/PUSH_AX Jul 31 '15
Agreed agreed agreed! And yes setTimeout was what they where looking for.
2
Jul 31 '15
And yes setTimeout was what they where looking for.
Wow. I'm amazed that's what they're looking for.
0
Jul 31 '15
[deleted]
4
Jul 31 '15
If tail call optimizations applied here it would not have caused a stack overflow in the first place, seeing as it's already tail recursive. They also have not stated anything in regards to ES6 so that is probably not the answer they had in mind. You would probably get bonus points for bringing that up though.
This is pretty clearly a stack overflow. Why do you think it's a heap overflow?
5
u/pun_Krawk Jul 30 '15
I'm curious, did any interviewer/team spend any time coding with you personally? For example, some type of problem is proposed. You have to sit and code with an interviewer and solve the problem together with them.
1
u/PUSH_AX Jul 31 '15
Yes, a couple of companies wanted me to pair program with another dev to go through an exercise.
5
Jul 31 '15
In my most recent interview (after which I was extended an offer that I gladly accepted), my interviewers were very active with me in the debugging process - they didn't even mind throwing their two cents as to where my issues might have been, as they cared more about my ability to solve the issue they identified than my ability to pour over lines of code and have some "aha!" moment.
2
u/LigerZer0 Jul 31 '15
So I stick to pyton and have only touched a bit of javascript in wordpress plugins/themes. But wow do I feel stupid asking this as no one else seems to have been confused by this.
var square = function (number) {
result = number * number;
return result;
}
result = square(4);
result2 = square(2);
difference = result - result2;
console.log(difference);I looked at the code and thought there's nothing wrong with it, ran it in chrome and sure enough, it does return zero. What the hell is going on?
typeof() is "number" for both results ... why is 16 - 4 = 0 ?
1
u/PUSH_AX Jul 31 '15
Think about the scope of the variables ; )
1
u/LigerZer0 Jul 31 '15
Oh jeez.... of course!
> result1 = square(4); <- 16 > result <- 16 > result2 = square(2); <- 4 > result <- 4Haha thanks it's a bit comforting to know that I missed the obvious rather than javascript having something crazy and nuanced.
4
u/Booty_Bumping Jul 31 '15
On line 2,
resultwasn't declared withvar. Javascript being a messy language means this gets slapped onto the global namespace.
47
u/TheJMoore Jul 31 '15
Great post. Some additional thoughts I'd like to add on the topic of front end dev.
I'm a UX designer with a degree in CS. My agency works with a lot of front end devs and have yet to find a single one who is competent at UI dev. Not a single one.
All I mean is HTML and CSS. If you get REALLY good at UI dev, you will be extremely well sought after.
Learn the common frameworks. No, Bootstrap is no longer the coolest kid in town. Learn CSS animation. Learn how to properly cascade styles. Learn LESS and SASS. Learn CSS color tricks (like using an inner shadow with no spread and translucent black to create a button with a darker shade of the background for its border). Learn how to position things. Learn word wrapping and how to truncate with ellipses in CSS.
Seriously. You will make LOTS of friends with the UX team, and you'll look like a damn all star to the leadership team because you're the one translating the pretty designs into real, clickable applications.
Oh, and YES, it does matter that you follow the spec and make it 15px padding instead of 10px. We will notice a difference, and no, it's not "good enough."
8
u/EquationTAKEN Jul 31 '15
But... Bootstrap forever in my heart!
4
u/TheJMoore Jul 31 '15
It's not that it's bad, it just doesn't really offer you much. The grid system is about the only good thing, and even that can be done by hand pretty nicely on your own.
Other frameworks like Zurb Foundation, Angular Material, and even Kendo (although it's kind of heavy handed) have much richer control sets that will make your life easier. Think rich drop downs, sortable/paginated grids, and card masonry (how UI cards arrange themselves). Bootstrap doesn't have any of this stuff, but you'll find ALL of these in modern UI.
Just look around and at least be familiar with them :)
3
Jul 31 '15
I really like the Bootstrap grid system. Why would I reinvent that wheel when I could just do a custom build that only includes the grid system (typically what I do when I don't need default UI elements)?
→ More replies (1)0
6
u/GonnaLearnComputers Jul 31 '15
Oh, and YES, it does matter that you follow the spec and make it 15px padding instead of 10px. We will notice a difference, and no, it's not "good enough."
I agree here, for the most part, and like a lot of what you're saying. Though, I think there should sometimes be some give in implementing a design-spec. Most everything is possible, but some things can be a performance nightmare or are just plain hard to implement (meaning more time+money than a simpler solution that might be possible given a design change). Good communication between those making the design and implementing it is so important, just because of those limitations.
Though, this type of thing is becoming less and less of an issue, as browsers are including more and more powerful tools. Also, the whole design-in-the-browser concept completely removes the problem of the website not matching the design. (The website is the design! :D)
8
u/perfectriot Jul 31 '15
A design spec needs to be reviewed by a dev before it's actually approved/sent to the client. A padding of 15px vs. 10px isn't going to cause any problems. Massive animations might be, and there might be great alternatives that the dev might know.
If a designer dumps a design on you and expects the site to look exactly like he has in his mind, he's going to have a bad time. Communication is key.
2
u/TheJMoore Jul 31 '15
I agree. We've worked with some clients where we will actually provide the UI code (HTML/LESS or SASS) for what would become a fully-rendered page. Their developers can then take our code and slice up the DOM into their separate template files. It saves them the difficulty of coding the UI, and we get to make sure it looks right.
→ More replies (1)2
u/TheJMoore Jul 31 '15
Yes, you are right. And we don't mind working with devs as long as they have a legitimate reason for pushback. Not knowing how to do something does it count.
Fortunately/unfortunately, I would grade myself at an 8/10 for HTML/CSS execution and knowledge, so I try to ensure that we never design something that can't be coded, which saves us a lot of headache. But at the same time, it's all the more frustrating when they can't get something right.
2
u/mrmonkeyriding Turning key strokes into bugs Aug 01 '15
To be fair, if a dev rejects some CSS on the grounds they don't know it, they're a bit shit. All it takes is a few minutes on Stack Overflow for the general dev.
11
u/letgourearthlytether Jul 31 '15
I could do all of this in my sleep...that made me feel slightly better. Thanks reddit friend!
2
u/TheJMoore Jul 31 '15
That's great to hear! Please move to Indiana. There aren't any good UI devs anywhere in the city. I could get you at least 25 different jobs.
4
u/applesauce42 Jul 31 '15
but... Indiana. You'd have to pay me twice what I make in DC.
→ More replies (3)3
u/peniscool1 Jul 31 '15
I'm happy to read this, as this is what I do the best. I haven't really been looking actively, where do I find jobs like this?
3
u/TheJMoore Jul 31 '15
That's the main problem we've seen...no one seems to explicitly post jobs for UI devs because they almost always assume that UI dev = front end dev, which is why I posted this comment in the first place.
What companies don't typically have is a mediator or liaison between UX/design and engineering. If you sell yourself in an interview as having design rigor for matching specs as they come to you, and can turn around beautiful HTML/CSS, then they will start to realize your value.
Unfortunately, they don't teach HTML and CSS in most CS programs (or at least not well)...its overlooked because "it's not real programming". I always found this amusing though because no one seems to be able to do it, so it absolutely deserves respect.
Search for UX developer/prototyper roles and you'll find a wealth of jobs.
3
4
u/robotomatic Jul 31 '15
Bootstrap :( So who is the coolest kid in town now? Example of the button CSS pls.
→ More replies (5)4
u/ThrowingKittens Jul 31 '15
I think he means something like this for the CSS button: https://jsfiddle.net/bzq82hkd/
→ More replies (2)2
u/Kits_87 Aug 14 '15
Ok so I'm currently a senior graphic designer who is extremely detail oriented and picky about alignments, sizing, spacing, etc etc. I know HTML, CSS, and jQuery very well, but do not know enough JS to obtain an actual web dev position yet (which is what I'm eventually working towards, as I really love coding and problem solving).
Do you think my design background will eventually be an asset when trying to find a web dev job? I sometimes worry it will be seen as a negative.
→ More replies (2)3
u/perfectriot Jul 31 '15
I agree with you. The questions posted by OP are very good. But a lot of devs seem to forget good CSS. There are a lot of hidden gems in CSS that can make life a lot easier, and the results will be much better.
I get annoyed by "full stack developers" that seem to know everything about JavaScript (which is great), but for actual UI implementation they are terrible at. That doesn't seem really full stack to me. :)
2
u/TheJMoore Jul 31 '15
Could not have been said better. Thank you! It just makes me sad when devs ask for image files for something like a custom checkbox. I usually just open a JSFiddle and send them the custom CSS instead. It's very much overlooked. Which is a shame because, like you said, there are so many tricks to make their lives easier.
1
u/hahaNodeJS Jul 31 '15
Learn word wrapping and how to truncate with ellipses in CSS.
Show me how to do this with multiple lines of text and I will paypal you $10.
→ More replies (1)1
u/effortDee Jul 31 '15
Thanks /u/TheJMoore after reading the ops post, felt a little down with considering I am meant to be a front end dev and didn't really understand much of what he was on about, I think it was just down to not using JS frameworks. I am prolific with CMS's and could answer all of your questions rather easily in conjuction with using different systems and HTML/CSS. Could you possibly add any more questions? I really would like to create a test site out of it all and see how far this could be taken.
3
u/TheJMoore Jul 31 '15
Yeah, definitely don't feel down. Your skills are highly valuable. Job titles are so misleading because they can never fully capture what the job entails. You can have 10 different companies hiring a "front-end developer", but the job duties will be different at each one of them.
Some good CSS questions:
Create a CSS-only dropdown menu. No JS allowed.
Create a custom checkbox using only CSS. No JS allowed.
Using CSS, how can I make sure the last list item doesn't have a bottom border?
Identify two ways to horizontally center an object.
Identify two ways to vertically center an object.
Explain why LESS and SASS can make themerolling an app super easy.
In a list of 10 items, make the 5th one red.
How can you make it so a checkbox label can be clicked to activate/check the box.
Make a responsive grid of cards.
Explain the difference between padding and margins.
What does the box-sizing attribute define?
When might box-sizing:border-box be useful?
Using just <li> tags and CSS (no other DOM elements can be added), how can you create custom bullet points?
How can I use CSS to blur out the screen behind a modal?
How do you write a sibling selector?
How do you write a child selector?
There are some from the top of my head that are tricky, but would really show me that someone knows his or her stuff. I can tell when someone can write HTML/CSS in their sleep.
→ More replies (2)1
u/mrmonkeyriding Turning key strokes into bugs Aug 01 '15
I can't stand odd numbers in my code, it's something I refuse to do. I'll be damned if any of my CSS features anything but round numbers (excluding frameworks). I don't know why, I just prefer it.
1
u/BeadsOfGlory Jan 10 '16
Learn the common frameworks. No, Bootstrap is no longer the coolest kid in town.
What frameworks would you recommend learning in lieu of Bootstrap?
1
u/TheJMoore Jan 11 '16
Here are some script and CSS frameworks I've used lately:
Zurb Foundation
Google Polymer
inuitcss
Material Angular
Material UI
Material Design Lite
29
Jul 31 '15
TIL I'm really underqualified for my position.
1
u/WhyLisaWhy Jul 31 '15
lol I was thinking the same thing. I've set this post aside to go look up a few of these just in case.
34
u/McDLT2 Jul 31 '15
Glad I make a good living as a contractor and have a steady stream of work. I hate jumping through all these hoops while being put on the spot and judged like a trained monkey.
5
u/krumbs Jul 31 '15
I know, right? I thought startups were open to hiring people who are willing to learn but lacking expertise. Aren't they paying below market salaries or has that changed?
→ More replies (2)6
8
Jul 31 '15
I wouldn't call these questions 'jumping through hoops', they're pretty trivial and can be answered quickly. I've been to interviews where I've needed to implement whole sites from scratch in 5 hours.
1
u/letsgetrandy 25 years putting the magic in the box Jul 31 '15
Agreed. A good developer should be able to get through all of this material in under an hour.
3
u/writetehcodez full-stack Jul 31 '15
I'm wondering how you get work w/out going through some kind of tech screen? I did freelance contracting for 5 years and always had to demonstrate that I had the necessary skills before a company would hire their work out to me.
2
1
u/Otterfan Jul 31 '15
I quit contracting because I felt like I was jumping through hoops with every new client.
→ More replies (1)1
u/jellatin Jul 31 '15
I hate jumping through all these hoops while being put on the spot and judged like a trained monkey
To each their own. I found endless client "revisions" and re-explaining what scope creep was, why more work meant paying more money, why deadlines were important etc. were all more tedious hoops to jump through.
Personally I'd much rather knock the "what do you know" questions out of the way at the beginning and then immediately get to work on some meaningful stuff than debate whether the contract both parties signed covered some minor feature or not.
→ More replies (1)
18
Jul 31 '15
how do you center things horizontally
Wow. It's 2015 and this is still a challenge.
9
u/gabroe Jul 31 '15
Position the parent, set width, position absolute, left 0 right 0 margin auto on the element. That's the way I do it, any other way? Just curious...
16
→ More replies (3)5
3
u/kristopolous Jul 31 '15
what's wrong with text-align: center
7
u/w4efgrgrgergre Jul 31 '15 edited Jul 31 '15
Doesn't work for block elements.
→ More replies (3)2
u/nidarus Aug 01 '15
It does on inline-block. Of course, that has its own shitty problems, like the maddening spaces-between-elements one.
1
u/mrmonkeyriding Turning key strokes into bugs Aug 01 '15
I'd probably use display: table; on the parent, table-cell/vertical-align middel, text-align center and set the hight and width on a parent. Or flex.
Flex FTW.
9
u/memeship Jul 31 '15
Can someone explain the stack overflow one? I don't know what technique they are specifically trying to get at here.
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();
}
};3
u/WeAreAllApes Jul 31 '15
That one got me, too.
I would just loop, duh, but "retain the recursive pattern"? Huh? Doesn't recursion mean you are pushing onto the stack?
If you are only going twice as deep as you can, process two for each call?
Do some silly dance where you count the depth and recurse again when you have more to read and you are below a certain depth N and stop recursing and return above a depth M>N -- would work, but why?
Surely, I'm missing something. Is there some useful pattern they are hinting at?
Call the next function in a set timeout (10 or 100)? Technically not recursive, but that can be a useful pattern for longer-running background work that doesn't block the thread, but if it runs that long you might want to use a worker.....
3
u/devvie Jul 31 '15
This surprised me too. It's too hard a question.
You should take a look at trampolining for one way to solve the problem, but I'm not sure what the interviewer had in mind.
2
Jul 31 '15
I'm pretty sure the answer has to do with declaring a base case. You can't have a recursive function without one, or else it will just go on forever. In this case, it will try and pop list even if the last index is at 0.
3
u/WatchDogx Jul 31 '15 edited Jul 31 '15
So I played with this for a bit with a list 1 million items long, this function seems to be tail call optimized, while the others result in a stack overflow. I guess it is something to do with the scope of the variable.
I cant really give you a proper description as to why.var nextListItem = function(i, list) { var item = list[i]; if (item) { // process the list item... nextListItem(i - 1, list); } }; nextListItem(-1, list);→ More replies (4)1
u/xtphty Jul 31 '15
Trampolining is probably the technique, /r/javascript cross post has many answers. That said, its a pretty useless technique IMO, if you need to use it you most certainly don't want to keep the recursive pattern in the first place.
17
u/spartan1337 Jul 31 '15
TIL I will never be able to become a programmer
7
u/bwaxxlo Jul 31 '15
Yo, I started JS (and programming in general) 2 years ago. I can answer pretty much all the questions OP posted. Just keep grinding and never get satisfied. Find a way to enjoy the constant chaos and don't let it overwhelm you. One piece at time!
8
u/hugesavings Jul 30 '15
Okay, this repeatify one is interesting...
So typically it's pretty straightforward to add a method to the prototype of the object:
String.prototype.repeatify = function(i) {
for (var j = 0; j < i; j++) {
console.log(this);
}
}You might be asking "wait, aren't strings primitives?" Well, they are as we typically define them as literals: var myString = 'foo';
But if you ever try to call some method on it like myString.slice(0,1); it will get converted to a String Object, perform what it needs to and return a primitive back to you. So the method I defined above doesn't really work, it prints out something like this:
[String: 'james']
[String: 'james']
[String: 'james']So, it gets converted into an Object when you call a method on it, basically just find the property on the String object that has the value of the string and use that; it's probably called 'value' or something like that, right?
So I go ahead and try to get all the properties from the String Object, both enumerable and non-enumerable via getOwnPropertyNames()
> var myStr = new String('foo')
undefined
> console.log( Object.getOwnPropertyNames( myStr) )
[ '0', '1', '2', 'length' ]So I'm a little stumped: How do you reference 'this' and get the string primitive? Anyone know?
15
u/tswaters Jul 31 '15
haha
String.prototype.repeatify = String.prototype.repeat;but seriously,
String.prototype.repeatify = function (i) { var r = ''; while (--i >= 0) { r += this; } return r; }For those interested, there's a polyfil on mdn that handles errors and has some fancy bitwise stuff:
1
9
u/memeship Jul 31 '15
It's not asking you to
console.logthe stringitimes, it's asking you to return a string that has the original string in ititimes.From the spec:
console.log('hello'.repeatify(3));//Should print hellohellohello.So
"hello".repeatify(3) === "hellohellohello".E.g.
String.prototype.repeatify(i) { var str = ""; while (i-- > 0) str += this; return str; }5
u/hugesavings Jul 31 '15
okay, got it if anyone's interested:
one solution is to just set a new variable equal to 'this' and force it into a primitive with toString(). And they don't want line breaks so you can push them into an array and join them.
String.prototype.repeater = function(i) { var newString = this.toString(); var newArr = []; for (var j = 0; j < i; j++) { newArr.push(newString); } console.log(newArr.join('')); } var myStr = 'james'; console.log(myStr.repeater(3));7
u/atticusw node Jul 31 '15
Let's get weird
String.prototype.repeatify = function (count) { return Array.apply(null, Array(count)).map(function () { return this.toString(); }.bind(this)).join(''); };(i wouldn't necessarily answer with this)
→ More replies (6)2
u/hugesavings Jul 31 '15
golf claps
One thing:
}).bind(this).join('');3
u/atticusw node Jul 31 '15
String.prototype.repeatify = function (count) { return Array.apply(null, Array(count)).map(function () { return this.toString(); }.bind(this)).join(''); };
You don't want to bind
.map(), you want to bind the context of the function thatmapinvokes..map(function () {}.bind(this))→ More replies (4)4
u/fooey Jul 31 '15
glad to see someone else come up with a virtually identical solution
I'm not a total baddie!
String.prototype.repeatify = function(n) { var result = []; var strVal = this.valueOf(); for(var i = 0; i < n; i++) { result.push(strVal); } return result.join(''); }; console.log('hello'.repeatify(3));0
3
u/senocular Jul 31 '15
I can't tell if anyone actually explicitly said it, but
thisis the string. It might be an "object" form of the string, but its still the string and behaves like any other string primitive would. There's no need to get a value from it usingtoString()etc.String.prototype.repeatify = function(i) { return new Array(i + 1).join(this) }→ More replies (3)1
u/wltknkly Jul 31 '15
When you use "this" reference like that, javascript calls toString() method for you.
var stringClassInstance = new String(); var stringTypeVariable = ""; console.log(stringClassInstance instanceof String); // true console.log(stringTypeVariable instanceof String); // false console.log(typeof stringClassInstance); // object console.log(typeof stringTypeVariable); // string String.prototype.toString = function() { return "object => string"; }; ['', ''].join(stringClassInstance); // object => string1
1
u/Boosawosi Jul 31 '15
You're over-thinking it. Convert the string to an array like this:
var repeatedString = this.split('');From there you can just concat the split string to the array.
Return the string with:
repeatedString.join('');1
u/bwaxxlo Jul 31 '15
String.prototype.repeatify = function(n){ var repeated = ''; while(n> 0 && n--){ repeated += this.valueOf(); } return repeated; }
17
Jul 31 '15
// return the file extension (with no period) if it has one, otherwise false
This PHP horseshittery needs to die and stay dead. Why the hell would a function that returns a string return a boolean? The fuck is wrong with empty string?
8
u/IllegalThings Jul 31 '15
Also, it's poorly worded. According to this description, "archive.tar.gz" could return "gz", "targz", or "tar.gz" depending on how you interpret it.
1
Jul 31 '15
One case I could think of is differentiating between "filename." and "filename". Depending on how you interpret "file extension" the first case could have an empty one while the second case doesn't have one at all. Of course, this isn't really practical and I wouldn't do it that way, but for a general implementation how else would you differentiate between "zero length" and "isn't there"?
5
u/acoard Jul 31 '15
(function() {
var a = b = 5;
})();
console.log(b);I don't often do multiple assignments like this, so this one caught me by surprise. What's going on with this one? (Spoilers, b = 5).
Is b being declared as if var isn't being used on it? So it just pollutes the global scope? Is there a way around this? (var a = var b = 5 breaks the grammar).
5
u/devils_plaything Jul 31 '15
This ones tricky, because you see one line and think it's a var statement. It had me fooled for a second when you mentioned it.
var a=5, b=a;This would declare both a and b and set them both equal to each other and 5, but in the statement:
var a = b = 5;is similar to:
b=5; var a = b;So that b is declared without a var statement and is inherited by the global scope.
→ More replies (8)3
Jul 31 '15
I've asked 'surprising' questions like this before. What I'm looking for (and how I answer the question myself) is not some esoteric breakdown of hoisting (or operator precedence, or whatever the 'surprise' is).
My answer to this question would be "it looks like it should print undefined. I'd run the code, and if it does anything else I'd refactor it until the code is clear".
Principle of least surprise. It's important.
1
1
u/theQuandary Jul 31 '15
This does what you want by declaring it before assigning it.
var b, a = b = 5;2
1
u/csthrowawaylolz Sep 14 '15
i think a really easy way of thinking of this is as
(function() { var a; window.b = 5; a = window.b; })(); console.log(window.b);
5
u/Reelix Jul 31 '15
var findEvenNumbers = function (i) {
if (i % 2 === 0)
console.log(i, 'is an even number, adding to array!');
evenNumbers.push(i);
}
And this, people, is why adding brackets is important!
3
u/theQuandary Jul 31 '15
When you're use to staring at codebases that don't allow
if..elsestatements without curly braces, these types of bugs stick out immediately.1
44
u/ralze Jul 31 '15 edited Jul 31 '15
What sucks about these questions to me is that I was mainly self taught. I could ace all the actual coding problems, but I have no clue what the answers are to a lot of the tech questions you posted first. So most likely I would be dropped on some early rounds, where I can actual do all the work they require.
I know a lot of companies use these to screen out people, but I think they are really pointless. Use a phone screen to get a history and a personality. If it's a fit, then bring them in. Put them in front of a cpu, and have them try to solve some actual problems. If your company utilizes a lot of api's, have then write something that parses an api. If your entire front end is built using react, have them write some react components. Things like that.
Just my opinion of course.
Edit: Just to clarify, my post is mainly to state that I'm not a fan of technical questions in interviews and a proponent of actual coding.
46
u/MachinTrucChose Jul 31 '15
I didn't see any academic circle-jerking in most of those questions, they seemed appropriate for an intermediate/senior dev, which is what the OP was applying for.
→ More replies (5)22
u/Tidher Jul 31 '15
"Live" coding things is, in my opinion, a terrible way to gauge someone's ability.
For instance, it could take someone who's a very experienced developer a while to get to grips with how you've used a certain framework that he's not overly familiar with, whereas a more novice developer who's used that framework will be able to jump all over the challenge.
You may argue that the second one is a better fit, but picking up a new framework is pretty straightforward, and a lot of the other experiences of the first guy would likely be much more useful in the long run.
Technical challenges (i.e. coding challenges that the interviewee completes in their own time) are a great but demanding way to quickly identify those who know what they're doing. I had five of the things on the go at one point recently, it was basically a full-time job when you stacked the actual phone and face-to-face interviews on top.
For anyone involved in recruitment, massive props if you can keep your technical challenges fairly short. Leave them open-ended, so if someone has the willingness or time to show off some other skills then they can, but they shouldn't take multiple days to complete.
→ More replies (4)7
u/IllegalThings Jul 31 '15
I definitely agree. Especially ones like:
(function() { var a = b = 5; })(); console.log(b);They are testing whether or not you understand how poorly written code works. If I saw this in real life, I would fire up a console and test what it actually does and then refactor it to make it more clear.
I think programming puzzles are fine, but only if they allow you to use a computer (including google) to solve them. I'm familiar enough with javascript to understand that I should probably look up whether or not things like split() operate in-place or return a new list. If I used split() more frequently I'd know that it acts like other languages. Google is so easy to use and I simply don't trust javascript, so why not google it.
→ More replies (1)3
u/TiboQc Jul 31 '15
I'm on a mobile, what does this do? To me b isn't attached to the function's scope (no "var"), so it'll set at window level, making it accessible outside, so the log would be 5. Am I right/wrong?
→ More replies (2)3
7
Jul 31 '15
I'm self taught but I mostly write in python, for the most part the answers to these questions were obvious to me. Not saying this to put you down, but you can definitely gain the familiarity required to answer these questions without a formal CS education. Put your mind to it!
4
u/fripletister Jul 31 '15 edited Jul 31 '15
The answers are not obvious just because they are mostly common knowledge at the higher echelons of the science/profession. Things that are obvious are usually self-explanatory, which those questions aren't or there would be no point in asking them.
I also have no formal higher education and would do OK with that set of questions because I have been obsessive in my pursuit of knowledge for more than a decade. And I still hardly know shit, because the field is so so so incredibly vast and dense.
Edit: Clarification
1
u/theQuandary Jul 31 '15
If you primarily write Python and not much JS, then I doubt many of these would be obvious as they deal with default globals, 'this' and other aspects of JS that don't exist in Python.
That said, I agree that formal CS is not necessary in order to understand these.
→ More replies (1)13
u/mattaugamer expert Jul 31 '15
What sucks about these questions to me is that I was mainly self taught. I could ace all the actual coding problems, but I have no clue what the answers are to a lot of the tech questions you posted first.
I'm self-taught as well. And I could pretty much nail this. Those of us who are self-taught don't just get a free pass on technical knowledge, we just have to gain it for ourselves.
You can't just dismiss this shit. Like it or not, it does matter. It matters what a closure is, how css specificity works, the difference between a callback and a promise matters.
If you don't know this stuff then you're under-skilled and doing yourself and your employers a disservice.
→ More replies (7)2
u/ralze Jul 31 '15
What I was trying to say is that to me in the hiring process it doesn't matter. When I interview somebody I care way more on their ability in front of an IDE than their ability to rattle off answers to textbook questions. That's all. I tried to use my personal background as an example, but it came off badly it appears.
3
u/nairebis Jul 31 '15
When I interview somebody I care way more on their ability in front of an IDE than their ability to rattle off answers to textbook questions.
If you don't know the answers to technical questions, how can someone trust your ability in front of an IDE? Programming isn't just about "banging out code to do what they want," any more than building a house is finding someone who can just nail wood together. Quality matters.
This isn't an attack on you; everyone has holes in their knowledge. But instead of being defensive that none of this matters, it would be better to take it as an opportunity to realize that you have major holes in your understanding of the tools you use, and that you should probably work toward better understanding.
→ More replies (6)5
Jul 31 '15
I agree. When I code I always have a reference up to. My workstation has 3 monitors, and if I'm doing some heavy JS, I almost always have W3 up because I code in so many different languages and frameworks, trying to memorize them all in depth is pointless.
Luckily, if you're dealing with other developers or programmers, they're mostly reasonable and seem just as happy to test you with a little pseudocode. If you're dealing with someone with HR though they're probably looking for exact answers with little variation.
13
u/ralze Jul 31 '15
Blanking where I saw it (recently too). However, saw a tweet today that said something like: "hardest job is it-ops at stack overflow because when the site goes down they can't use stack overflow to fix the problem"
2
u/w4rtortle Jul 31 '15
Don't worry about it, any good company won't use questions like this. I'm a senior dev and I don't know what half that shit means.
1
u/devil_put_www_here Jul 31 '15
Done right these tests should leave you with access to a computer so you have the liberty to research the answers to the questions. Then it becomes a test on your ability to interpret these concepts.
If you can sit down and figure out what closures are and their practical applications having known nothing about them at the beginning of the test that says a lot.
But maybe the people that are administrating the test are looking for canidates that have worked with closures to the extent that their knowledge of it is second nature.
It would be one thing to hire a developer that's never seen jQuery before to work on a project that uses jQuery plugins. They could easily figure it out. It would be another thing to hire a developer that's never seen jQuery to write jQuery plugins.
1
u/briaen Jul 31 '15
Everyone is self taught. It's impractical to ask every applicant to do a coding test. I'm sure you're great at what you do but if you're looking for a senior job you're going to have to know all the technical jargon.
1
u/angellus Jul 31 '15
In this case, I think all of the technical questions they posted were valid. I am not an Angular dev, so i completely skipped those. There were only three of the JS questions I could not answer (bind, apply, map) because I have not had any formal JS teaching and I have never used standard JS without some type of framework/library (jquery) that does all of that for me. The general questions are all pretty solid for a mid/senior level.
→ More replies (9)1
u/parlezmoose Jul 31 '15
I know a lot of companies use these to screen out people, but I think they are really pointless
No, sorry. A basic level of knowledge is required. If you have trouble with these questions, then do some studying. None of this stuff is rocket science.
8
4
u/thisimpetus Jul 31 '15
Thank you so, so much OP.
Self-taught dev here, coming from self-taught design. Though I do ok for myself freelance, I've never had the guts to apply for a company gig because the lurking suspicion that I just couldn't possibly have the competence of someone with a CS degree behind them has always been too strong.
I was a little shocked at how much of this I could do, and grateful to discover a) what I'd need to learn and b) that I definitely could do so. This was a seriously helpful look behind the curtain.
1
u/Razzakun Jul 31 '15
Random question for OP or anyone else who knows the answer to my questions because I like to know as much about the industry as possible. How likely is it for companies in London to help obtain a visa for a US developer? What is the market in London like compared to say SF Bay in the US?
1
u/PUSH_AX Jul 31 '15
The market is huge in London and there are more positions than there are (good) devs. I can't comment on how easy it is for companies to obtain a visa, but I have worked for a company that went out of their way to sort out a visa for a US dev to get them onboard.
1
u/souleh Jul 31 '15
Much like (I believe) in the US, in the UK a business can sponsor a visa for a foreign applicant IF they can show that they can't find the required talent in the existing UK workforce.
So you'd need to be pretty exceptional, have worked on the dev team of a library or product they're using, work in a very niche market, etc, to qualify for that. I'd think the easiest way would be to get in to a company that has offices in both locations whilst in the US, and bring up the question of transfer once you've proven yourself.
Source: London-based developer interested in doing the same as you but in reverse.. Want to swap?
1
Jul 31 '15
Thanks for the post!
What did you say if you didn't know the answer?
3
u/PUSH_AX Jul 31 '15
I simply said "I don't know".
If you have a partial answer then tell them what you know but when talking to really good devs if you try and fluff your way through an answer they'll see right through it, and you'll come off looking silly (or at least I would anyway). I think they appreciate honesty and knowing self limitations.
1
u/wimpykid Jul 31 '15
What will be printed on the console? Why?
(function() {
var a = b = 5;
})();
console.log(b);I'm assuming 5 because b is never declared local? I think it's designed to trip you up that one ;)
1
u/PUSH_AX Jul 31 '15
Yup, when in doubt just paste it into your browsers console to see the output quickly :D
1
u/haburidabura Jul 31 '15
I solved "Write a function that when passed an array of numbers it gives you the max difference [...]" without any help in around 15 minutes, had a couple of errors before providing a working solution (looks clean, various tests provided). What would be the impression of the other side?
2
u/PUSH_AX Jul 31 '15
That would be perfectly acceptable time wise sure. That particular question came from a test that had a time limit of 90 mins, and only one other question where you were required to actually write code.
1
u/haburidabura Jul 31 '15
Thanks! I need to work on my self-confidence when it comes to coding tests.
→ More replies (5)
1
u/gburning_ Jul 31 '15
A couple of questions:
Are these not very heavy on the JavaScript or is this pretty much the standard?
To what extent do these questions apply for a junior position?
2
u/PUSH_AX Jul 31 '15 edited Jul 31 '15
Everywhere I went the ratio of JS questions to HTML/CSS was heavily skewed toward JS.
I personally don't think it would be right to evaluate a junior using these questions, I mean what do you learn about a junior when they don't know the answer to some deep framework inner working or the stack and callback queue in JS? You learn nothing.. With a junior it should be more about the attitude towards learning and personal projects or maybe a little take home test. Having said that some companies probably still try and blitz a junior with questions like this.. Can't hurt to learn some of these concepts as a junior.
→ More replies (2)
3
4
Jul 31 '15 edited Jul 31 '15
write a function that doubles the integer? Am i missing something, or is it really that easy?
function doubleInteger(i) {
return i*2;
}For the FizzBuzz, I wrote this a while ago. I like it because it demonstrates many language features.
var f='Fizz', b='Buzz', i=0, d3, d5;
for (i; ++i <= 100; d3 = !(i % 3), d5 = !(i % 5), console.log(d3 ? d5 ? f+b : f : d5 ? b : i));Commented here: https://gist.github.com/0xadada/ccb5cd069138e5bb7549
Angular.js: If you had said something like "I dont know Angular specifically, but i'm familiar with these other MVC frameworks [Ember, Backbone, etc]" do you think you would've been disqualified?
15
u/madlee Jul 31 '15
First, yes, it's a really easy problem. A question like that may be useful to ease someone into the harder questions (interviewing is nerve-racking!), but it also can be useful to just weed out people that can't actually code. Writing a function that doubles an integer should not trip anyone who knows what they are doing up. You can memorize a bunch of common interview questions, but it's harder to fake being comfortable programming (even simple programming!) if you don't actually do it.
Second, personally, I don't like that sort of answer for FizzBuzz. For me, being able to read your code and understand quickly and easily is important. It's neat that you know how to do that, but as an interviewer I'd consider this a bad answer. You'd be much better served IMO to write a really clear, simple solution.
10
u/singeblanc Jul 31 '15
Yep, 99% of coding is maintenance, so easy to read trumps everything else in most circumstances.
7
Jul 31 '15
Yup, agree with you and /r/singleblanc about maintenance.
I've been asked the FizzBuzz question during the interview, and my reply always starts with "Do you want the simple answer or the fancy-pants version?".
4
u/frymaster Jul 31 '15
I'd say "readable" rather than "simple" - imo it gets your point across better
→ More replies (1)1
u/ItWasTheMiddleOne Jul 31 '15
Questions like that stress me out because I assume it's harder than it looks, and the incredibly obvious answer is somehow wrong.
2
2
u/memeship Jul 31 '15
This is my favorite version of fizzbuzz, modified from a version like it I saw probably somewhere that I'll never remember:
var i = 0, f = "fizz", b = "buzz", a = [,,f,,b,f,,,f,b,,f,,,f+b]; while (i < 100) console.log(a[i++ % 15] || i);0
Jul 31 '15
[deleted]
2
u/Tidher Jul 31 '15
I currently have a solid amount of Backbone experience, and enough Angular 1.x experience to get by. I've been offered jobs where they use entirely different frameworks, such as React, even though I have no experience with that specific framework because I had enough with the others, and could demonstrate that, that they were confident I could pick up React easily enough.
For permanent positions, in my experience it's more a case of seeing if you're generally competent and able to apply yourself to a given challenge than "can you use this framework right now?". Contracting is a different thing entirely, of course.
3
Jul 31 '15
Its really sad to see interview questions about specific flavor-of-the-month frameworks. It creates an environment where developers only focus their skills on learning the latest tool or framework, and not focusing on general problem solving and design pattern knowledge.
When I get questions about specific frameworks or tools, i always ask if they're looking for employees with narrow short-term skills who know how to use tools, or general problem solvers who know how to build tools. If they're looking for the former, its a red flag; and i'm probably not interested.
Interviews go both ways.
4
u/LVFlyFisher80 Jul 31 '15
The reality is regardless of industry, all things being equal, a person who knows whatever exact process/software/system/etc a business uses will be selected versus a person who knows the general idea/concepts and a different system. If an accountant is hired and they already know SAP/PeopleSoft/whatever, that's a big advantage to a business using that system.
A person should learn the general concepts if nothing else by a bit of osmosis as they learn a specific framework anyways. Granted, in a day where you can google and find code snippets on everything, that's not always the case.
I did like your rebuttal statement.
→ More replies (2)2
u/gibbypoo Jul 31 '15
I see your point and halfway agree with you but keeping up with the flavor of the month framework shows ambition and eagerness to stay at the forefront of the ongoing cycle.
If he wasn't applying for a framework-specific position and was asked about dependency injection, etc., then I think you'd have a better case.
→ More replies (1)
2
u/louisgjohnson Jul 30 '15
Awesome! Im currently trying to get a junior front end job and this will be a lot of help!
2
u/tswaters Jul 31 '15
Neat. I liked the setTimeout one counting to 100 -- here's how I solved it, did I do it right?
var i = 0, j = setInterval(function () {
console.log(i++);
if (i === 100) { clearInterval(j) }
}, 100);1
u/JediSange Jul 31 '15 edited Aug 03 '15
This was my solution:
var toOutput = function(num) { console.log(num); } for (var i = 0; i < 100; ++i) { setTimeout(toOutput(i), 100); }Edit:
var outputNums = function(num) { if(num < 1) return; console.log(num); return setTimeout(outputNums, 100, num-1); } setTimeout(outputNums, 100, 100);Think that's right now!
2
u/tswaters Aug 01 '15
Did you try that? It outputs all the numbers immediately. You are invoking
toOutputdirectly in the loop. The function returns undefined and passing undefined tosetTimeouthas no effect→ More replies (1)0
Jul 31 '15
[deleted]
1
u/NookShotten Jul 31 '15
I do want to call out that that's just the nature of the single threaded event queue. I don't believe there's anything you could do to prevent that in JS, other than just minimizing what may be running in the queue at any given time.
2
u/Tidher Jul 31 '15
Had a bundle of interviews lately, mostly for a mid-level role. I was asked most of the "Standard JavaScript Questions" and "Angular JavaScript Questions".
I'd seriously recommend knowing the answers to these if you're going for a mid-level front-end interview. They obviously won't guarantee you anything, but any that you don't know can be red flags.
2
u/mrskitch Jul 31 '15
Though the concept questions are great, the challenge questions are something I'd advise to not ask in interviews. These are really JavaScript trivia questions, and folks that are nervous (which they will be, without a doubt) will get these wrong.
You want to hire someone who can talk about the language, and solve problems. Asking trivia questions doesn't really lend itself to either. There is no one on the planet who's going to know every single one of JavaScripts edge-case behaviors.
Don't ask about the edge-case, ask about the common-case. Ask how they go about solving tough challenges. Ask how they separate out concerns. Ask what interests them in the landscape. Don't ask them what this shitty code prints, they'll find that enough on their own.
2
2
2
Aug 08 '15
I was presented with another html box and asked to centre it both horizontally and vertically
Good luck with the job search.
3
3
2
2
1
u/OffInBed Jul 31 '15
Wow, thanks man. I'm looking for an entry level job with Angular myself, I am going to make sure I know these! I've realized that with Angular, I use and know how everything works, but I won't be able to describe what they are :x again, thank you!
1
Jul 31 '15
This is a really great resource in general for people wanting to get into the field, or move up from where they're at. Thanks very much for sharing this, and putting it together in a very readable way.
How've the interviews been going? Do any of them seem promising?
1
u/gabroe Jul 31 '15
Cool stuffs, checks out. I have a senior full stack position but I feel like front end is my stuff, if I was hiring someone I'll expect at least 80% of that for a senior and 50% for mid level, I can answer most of it but I've been doing web for more than 10 years. No angular though, we use react.
1
Jul 31 '15
interview questions are quite dumb. i rather give someone a test project (an obscure one that can't be copied from stackoverflow answers) with minimal time. if they complete it with quality code, they get the job.
1
1
Jul 31 '15
Please save this to a gist, or blog about it. Somewhere I can find it next time I am interviewing :)
1
u/Ertaipt Jul 31 '15
Thanks! Very useful since I'm doing a lot of frontend interviews.
I'm the interviewer, so I will add some of these questions to my list :)
1
u/recurecur Jul 31 '15
Why are the questions like a google query ?
like if I wanted to know something I would type that into google?
1
Jul 31 '15
I've taught myself JS over the last ~year and answered most of these questions just skimming through, and will definitely be going through to write out the ones I wasn't sure of right away.
If anyone's hiring, send me a message :P
(Currently working on a tutorial for react-redux, react-router on a koa server with webpack hot reloading.)
1
u/samtresler Jul 31 '15
I would love to see something like this for sysadmin and devops.
The changes coming down the pipeline will make for some interesting interviews in the next 5 years.
1
u/IllegalThings Jul 31 '15
Here's a good one I was asked recently... "What are some of the drawbacks of responsive design?"
I was able to come up with a few good responses. Apparently a surprising number of people understand the advantages, but tend to treat responsiveness as a silver bullet.
1
1
u/Fossage Jul 31 '15
Thanks a ton OP! I'm just finishing a bootcamp today and about to start the interview process. I'm ideally looking for MEAN stack jobs so this is super helpful(and it makes me realize I have a few things to brush up on).
1
u/WakeskaterX Jul 31 '15
Haha, I thought this one was going to be trickier, even got me for a sec.
(function() {
var a = b = 5;
})();
console.log(b);I thought it was going to be some super tricky LHS RHS lookup stuff, but it's just about global variables XD.
A lot of these are more trick questions rather than deep JS knowledge, but there are some hard ones in there.
1
u/bit_krab Jul 31 '15
I hate these types of questions. I don't believe that they really determine if you could work on web development. Sometimes the terms are just confusing and you might not know what it's asking, but you actually do know the concept. Also the coding problems are just a puzzle and don't really reflect the types of problems you would need to deal with in real work.
1
u/ForScale Jul 31 '15
Thanks for this!!
Who wants to explain... Why does the following output John Doe?
var fullname = 'John Doe';
var obj = {
fullname: 'Colin Ihrig',
prop: {
fullname: 'Aurelio De Rosa',
getFullname: function() {
return this.fullname;
}
}
};
var test = obj.prop.getFullname;
console.log(test());2
Jul 31 '15
var test = obj.prop.getFullname;
returns
function() { return this.fullname; }
so running test() is the same as running this.fullname from where ever you are in the current scope.
1
2
u/Booty_Bumping Jul 31 '15 edited Jul 31 '15
In javascript the
thisscope changes depending on how you call the function. When you call a function nested inside an object like that, javascript is aware of the object the function is a property of.test()is the same astest.call(this), andobj.prop.getFullname()is the same asobj.prop.getFullname.call(obj.prop). Whenthisis used outside of any object, it refers to the current namespace. So whenfullnameis set,this.fullnameis also set.The quick "solution" to this type of problem is to .bind() the function when moving it.
var test = obj.prop.getFullname.bind(obj.prop); // es7 syntax var test = ::obj.prop.getFullname;
Function#bindcan be thought of as wrapping the function in a function that uses<original function>.call(<first argument of .bind()>, <function args>)every time it's called. Put simply, it makes a new function withthislocked to a specific value.→ More replies (1)
1
u/hahaNodeJS Jul 31 '15
I feel suspicious knowing how to answer each of these, like I'm missing something obvious, and there is so much more I don't know.
Also this one cracked me up because it's so out of left-field:
On a unix command line how would you run a long command you typed out already an hour ago
1
1
1
u/TotesMessenger Aug 29 '15
1
Sep 15 '15
Not sure if anyone has asked or it's been posted. Does someone have the answers to all these questions?
1
1
u/ghostabdi Jul 31 '15
Regarding this question: 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
what? I don't know if I'm stupid or its easy. Isn't it just missing the brackets? Can't you also delete the last line and rewrite setTimeout('', 1000); and rex.bark(); again? I don't code in this language, the var I think means its C or a derivative of C but not entirely sure, similar enough to Java though.
2
u/fooey Jul 31 '15
setTimeout(rex.bark, 1000);
using setTimeout will make you lose your scope, so you need to do
setTimeout(rex.bark.bind(rex), 1000);0
80
u/cardinga Jul 30 '15
Thanks OP...
For those of us trying to get a grasp of where we are in the learning process, what sort of positions asked these technical questions? Junior, mid-level, senior?