Here are a few of my favourite interview questions which I think a candidate should at least have to be familiar with.
- What is the difference between == and === ?
- most basic question, good for a warm up
- === checks for type too while == does not.
- Type conversions
- That's a tricky one, lot of questions can be created. You have to try yourself, but here are some examples
- "1"+2+3 --> "123"
- 1+2+"3" --> "33"
- true + "2" -- > "true2"
- true + 1 --> 2
- false + true --> 1
- function something(){} + 1 --> 1
- undefined + null --> NaN
- etc...
- What are closures?
- "Closures are functions that refer to independent (free) variables. In other words, the function defined in the closure 'remembers' the environment in which it was created."
- I prefer this definition more: "A closure is an inner function that has access to the outer (enclosing) function’s variables—scope chain. The closure has three scope chains: it has access to its own scope (variables defined between its curly brackets), it has access to the outer function’s variables, and it has access to the global variables. "
- Expect some tricky questions, a typical one is here the 3rd point. As the page says also, you have to surround the critical code with IIFE.
- What is IIFE?
- Immediately Invoked Function Expression
- Basically helps create an own scope for your code.
- (function something(){})()
- Design Patterns
- I think what this is the most important one. Most of the JS developers think that they don't need any patterns at all. But the point is that's what distinguishes good developers from bad developers. Here are some of the most used patterns. (You can find some good descriptiones here.)
- Module (Revealing Module)
- Observer (event loop)
- Facade
- Singleton
- Factory
- ...
- What is the event loop?
- How the browser handles events. Basically if an event appears, the browser will not stop the execution of the current script, instead puts it in the event queue, and when finished this script, gets the first event from the queue, and executes it's callback
- A very good visualization is here: http://latentflip.com/loupe/
- Prototypical Inheritance using ES5
- You can see my blog post about this topic here: http://nagyadam2092.blogspot.hu/2015/03/oop-in-javascript.html
- What are Promises?
- "A promise represents the eventual value returned from the single completion of an operation."
- Basically offers a much better way to handle errors like callbacks when calling asynchronous methods.
- You can read more here: http://www.html5rocks.com/en/tutorials/es6/promises/
- What is 'this' in the following example?
- Most of the examples are pointing if the interviewee knows if 'this' is pointing the global variable (in browser it's the 'window' object)
- good article: http://www.quirksmode.org/js/this.html
- Mention some basic algorithms (code it as well)!
- sorting algorithms
- fibonacci
- computational complexity (O(n), O(logn), ..)
- Turing machine
- Git
- You have to be familiar with Git. From command line.
- Here is a good cheat sheet: https://training.github.com/kit/downloads/github-git-cheat-sheet.pdf
Good article on design patterns:
ReplyDeletehttps://blog.risingstack.com/fundamental-node-js-design-patterns/