Preparing for an interview can be stressful, and even more so if you don't feel you've put the right preparation ahead of D-day.
Here are some questions you should be prepared to answer:
You didn't expect that one, right? Yeah that one can come up. It's unlikely and a bit too scholar but it can get you on the wrong path if the interviewer feels that you have no idea what JS is about from the very beginning of the conversation.
That's the follow-up question for the 1st one. Keep it up.
Possible answer - It allows less server interaction ; you can validate user input before sending the page off to the server. This saves server traffic, which means less load on your server.
- It allows immediate feedback to the visitors ; they don't have to wait for an entire page to reload to see if they have forgotten to enter something.
- You can add interactivity ; for example having an interface that reacts the user hovers over an element.
Now the more serious stuff.
Q - What is a callback?
Might not make sense right away but try replacing functionA() with puttMyClothesOn() and functionB with goToWork()...
Getting the picture?
A function that takes other functions as arguments or returns functions as its result is called a higher-order function, and the function that is passed as an argument is called a callback function. It’s named “callback” because at some point in time it is “called back” by the higher-order function.
Michael Vollmer explains it really well in his post.
Q - What is a closure?
If you don't get that question during your interview.... well that's just not possible, you will get that question for sure. You might not get that on the very first interview but you will get it at some point.
Imagine you want to use a variable for counting something, and you want this counter to be available to all functions.
You could use a global variable, and a function to increase the counter:
You need a way to prevent the variable counter from being changed/altered without using the add() function but also you need the counter to be called only once if needed so it's not really a solution to modify your function with += 1 addons.
The solution is to use a closure.
The variable add is assigned the return value of a self-invoking function. The self-invoking function only runs once. It sets the counter to zero (0), and returns a function expression.
This way add becomes a function. The "wonderful" part is that it can access the counter in the parent scope.
The counter is protected by the scope of the anonymous function, and can only be changed using the add function.
Possible answer - A closure is a function having access to the parent scope, even after the parent function has closed. It allows to protect a variable from being changed while allowing a script to use via a function.
Practicing is your best bet here so don't hesitate to Google for mockup interviews and tutorials on this.
Here's a great video from Codementor.io YouTube channel:
This video is great and Dan is really giving a great overview of what most screening interviews will be look like. I can't stress enough the importance of his advice here.
You should always be communicating about what you are doing, how you are assessing the situation while you're in the coding challenge, exercise.
Remember that the interviewer is not looking for a human MDN here (check out my resources post if you don't know what MDN is) but want to see how you think, how you use your current knowledge and experience to tackle a problem you've never encounter because that's what programming is all about.
Your ability to communicate on what you are currently doing is also crucial to prove to your interviewer that you can take a few steps back and have a critical eye on a problem.
Feel free to comment if you liked that post and let me know what you think or tell me about an interview!
PS: I'll be adding more questions and refining that post. I'll be writing about more in-depth questions and the exercises you can be asked to solve during an interview.
PS2: I know I was supposed to post a video on how to replicate the Facebook landing page but I'm still waiting on Amazon to deliver my microphone. 😎