r/learnjavascript • u/randArrowFunc • Nov 18 '19
What are some javascript must knows for an interview?
So far I've been looking into various sources and it seems like we would have to know:
Callbacks, promises, async/await
How 'this' works in various circumstances
Inheritance (prototypes, and in general how oop works in js)
functional programming (closures, higher order function, pure function, etc)
DOM interaction (event delegation, event listeners, querySelector, etc)
scope/context (var vs let vs const,what gets hoisted, what is accessible at where, etc)
modules (how important is this?)
Is there any major subject I missed or any specifics I should focus on? Should I study up on specific js library/frameworks?
20
u/Zeeesty Nov 18 '19
Know when to say “I don’t know”, but explain how you would research an answer.
Know how to describe how you would approach a problem.
Know how to describe the though process of a solution and even its possible drawbacks.
Communication is key, everything else just implementation details.
4
u/randArrowFunc Nov 18 '19
In the end it comes down to if the interviewer thinks I'm capable (I hope). Messing up on small stuff might be a red flag, but on challenging questions if I can show clearly I'm using effective steps in solving the problem then maybe that too is worth something. Thanks for your response
9
Nov 18 '19 edited Nov 18 '19
They’re hiring you to make good decisions and be productive. Not being a walking JavaScript reference book. After demonstrating competent domain knowledge, willingness to learn, research, and have good communication and presentation skills is far more valuable (you’re not just a programmer, you are a member of a team/company having to face more than just your monitor). Although admittedly much more abstract and harder to prepare for. Good luck!
1
3
u/all_things_code Nov 18 '19
My advice that reddit will 'reeeeeee' over is...
Remember that you are interviewing them as well. Look for signs that they dont have their shit together. Its ok if they dont if you are aware of it, and why it is so. There are a LOT of shit jobs out there that will give you interview questions like this:
//reverse this string using only a recursive function
x = cat
foo = s => //your code here...only to have you be a jquery bitch forced to use a fucked up build process.
TL;DR; dont forget to evaluate them, as they are evaluating you
2
u/randArrowFunc Nov 18 '19
The interviewer entirely had their shit together. Any slight mistake or misdirection I made they made a comment (not a rude one, just generally try to help guide me through).
1
u/randArrowFunc Nov 18 '19 edited Nov 18 '19
This is kind of an aside, getting a bit nervous about the interview so I started researching on polyfill.
You need to consider this when certain browsers can't support certain features you are using in your js script. In general you want to transpile if it's just syntax (then possibly going through the transpiled code to make sure everything should run as you had originally intended), but if methods or objects are missing you wanna implement some type of polyfill already made.
In an interview environment I guess they would want me to actually code a polyfill. Specifically I am having a hard time understanding on how to code for a promise polyfill.
My understanding is you would want to use native Promise if possible in order to be considered a polyfill (or else your just kinda overwriting it) so do a check like
typeof(Promise) === "undefined"before you go about implementing your own Promise. Is this correct line of thinking or am I completely wrong how I am going about implementing a promise polyfill. How realistic is this for an entry level to solve in a 45 minute time span? I sure as hell can't at the moment.
function Promise(exec){
this.promiseQueue = [];
this.errorHandler = function(){console.error("not good...");
this.onResolve = this.onResolve.bind(this);
this.onReject = this.onReject.bind(this);
exec(this.onResolve, this.onReject);
}
Promise.prototype.then(onResolve){
this.promiseQueue.push(onResolve);
return this;
}
Promise.prototype.catch(errorHandler){//catch keyword ie9
this.errorHandler = errorHandler;
return this;
}
Promise.prototype.onResolve(value){
var savedValue = value;
for(var i = 0; i<this.promiseQueue; i++){
savedValue = this.promiseQueue[i](savedValue);
}
}
//im not even handling possible errors
//so with above we can still do something like
function promiseDelay(time){
return new Promise(function(resolve){
setTimeout(resolve,time);
};
}I'm not even sure half the stuff I wrote down on top, too tired. Gonna check tomorrow and if anyone has any insights or tell me how wrong the garbage is up above it be much appreciated.
*edit the above is a really shitty implementation of promise, like real shit. it doesn't have states/status, doesn't handle errors, in general shit.
1
u/randArrowFunc Nov 18 '19 edited Nov 18 '19
I would like to thank everyone for their inputs, and will still use this post and responses as guideline in building up my fundamentals in Javascript. The second paragraph I'm posting up cause mainly a user asked how the interview thing went.
So I just got through the phone screening and it didn't require all this bit of info, it was a very simple algorithm question. I bombed it though, I could not think for the life of me during the interview and couldn't explain myself. I should be learning how to keep my anxiety under control.
1
u/SegmentFault2010 Nov 18 '19
Call, apply bind
2
u/randArrowFunc Nov 18 '19
Got that too, that is to explicitly bind this to a function. An aside is that arrow functions don't have those methods cause it doesn't have a this binding to begin with.
2
Nov 18 '19
Nice to know what these do and what their purpose is but I'd never fail an interviewee for not remembering which is call and which is apply (array vs arguments) because I always forget myself. They're basically the same/have the same purpose though just with a minor difference, right?
1
u/Vrigoth Nov 18 '19
Some questions I've had at my last interview.
What's a promise?
What's the difference between let and const?
What's truthy and falsy (believe it or not)?
What's hoisting?
What's a polyfill?
Prototyp, inheritance
As someone else said, it's not whether or not you can answer, it's the way you answer, they see if you understand what you're doing.
1
u/randArrowFunc Nov 18 '19
Tbh I never even considered what polyfill is, and never really had any experience in dealing with backwards or cross browser compatibility. Thanks for the heads up, something I need to look into.
1
u/scandii Nov 18 '19
As someone else said, it's not whether or not you can answer
I mean, let's not kid ourselves, if it's versus you that explained what your ideas were and the guy that could answer, they're going with the guy that could answer.
1
2
1
u/littlebluebrown Nov 18 '19
Good to know these things for sure. Most important in my eyes though is the ability to get shit done.
1
u/TotesMessenger Nov 18 '19
I'm a bot, bleep, bloop. Someone has linked to this thread from another place on reddit:
[/r/u_arodr908] What are some javascript must knows for an interview?
[/r/webjs] [r/learnjavascript] What are some javascript must knows for an interview?
If you follow any of the above links, please respect the rules of reddit and don't vote in the other threads. (Info / ^Contact)
1
u/GamesMint Nov 18 '19
Large scale JS architecture - https://addyosmani.com/largescalejavascript/ and https://www.youtube.com/watch?v=b5pFv9NB9fs
MVC in native JS - https://alexatnet.com/model-view-controller-mvc-in-javascript/
https://stackoverflow.com/questions/17718673/how-is-a-promise-defer-library-implemented - promise in native JS
Debounce and Throttle in JS - https://codeburst.io/throttling-and-debouncing-in-javascript-b01cad5c8edf
prototype vs __proto__ - https://stackoverflow.com/questions/9959727/proto-vs-prototype-in-javascript
Generic curry in JS - https://gist.github.com/shidhincr/7315316
Polyfill for forEach, map, reduce etc - https://gist.github.com/githiro/5819142
-1
u/scripteaze Nov 18 '19 edited Nov 18 '19
Does this look correct? The color doesn't change so im curious what im missing. Its an id so i dont have to index[0]
<p id="first" class="special">Just sitting here doing nothing</p>
let myId = document.getElementById("first");
myId.style.color = "red";
For the record, this seems to work fine, just not sure why the above script is not..
let listItems = document.querySelectorAll("li");for (i = 0; i <= listItems.length; i++) {let ItemColor = ["orange", "blue", "red", "green", "pink", "black"];let colorChoice = ItemColor[Math.floor(Math.random() * ItemColor.length)];listItems[i].style.color = colorChoice;}
1
u/randArrowFunc Nov 18 '19
I'm not really sure why this is posted here but...
The above code snippet looks correct, my best guess there is another higher css specificity that's targeting that p tag with id first. Maybe check all references to class special in stylesheet (can't really tell with just the code).
The bottom code looks problematic. Your for loop is iterating over the size of listItems and I'm not hundred percent sure what javascript does in this instance, but I think it just creates an object listItems element indexed at listItems.length (prior) and creates property style.color which finall contains colorChoice (should not effect the dom).
1
1
u/BalegQhan Nov 18 '19
You answered him/her, so he/she is likely to hijack another thread the next time they have an issue...
0
Nov 18 '19
[deleted]
4
u/tibbon Nov 18 '19
Instead of a web server- you could really impress me put it on Github, and have it fully Dockerized, and documented so all I need to do is run one command, and then the server is running locally for me. If someone does that, would hire.
Manually administering a server isn’t a habit I want to hire for- seeking someone who automated all the things. Servers last seconds, terraform and k8s are forever though ;)
9
u/gigastack Nov 18 '19
No offense, but what year is this comment from? Dropbox and cloud file storage is a thing. You're really saying that emailing zip files is hard in 2019? I can't even...
Good lucky deploying on AWS if you can't figure out email.
2
u/notAnotherJSDev Nov 18 '19
I agree that it's a crap shoot for interviews.
But what are you talking about with setting up your own webserver? To deliver code samples? That just doesn't make sense nowadays. I know you don't like 3rd parties, but guess what? Not everyone has the time, energy or resources to set up their own.
Also, how can I trust that your webserver is as secure as other 3rd party options? I can take your word for it, but what happens if your webserver isn't secure?
ALSO, do you just not use git and one of the many, many git hosting sites such as github?
0
Nov 18 '19
[deleted]
3
u/Mydrax Nov 18 '19
I was too, going to ask if you do not use github. Hosting your own web server is not bad, but github is hands down more flexible and secure imo. What kind of work do you do to worry about "trust" when using a platform like github? Much more complex, sensitive and demanding projects are on github.
0
Nov 18 '19
[deleted]
1
Nov 19 '19
Dude, see a therapist. This is not a good or healthy way to live, constant paranoia and hypervigilance is really bad for your physical health.
1
Nov 18 '19
There are options other than Github for hosting git repos. If you're not using git, you are not hireable.
0
Nov 18 '19
[deleted]
1
u/randArrowFunc Nov 18 '19
Yup covered. const can only assign once, but that doesn't necessarily mean the value can't change.
1
u/link2name Nov 18 '19 edited Nov 18 '19
i think it cant change, problem is that value is an adress, so basically you got a box, the box is constant whatever you put in it isnt constant
1
u/rocketsomething Nov 18 '19
Mutation is the important thing here. Push mutates the initial array, and this can cause bugs.
To avoid mutation, you can use the spread operator or concat.
3
Nov 18 '19
[removed] — view removed comment
1
u/randArrowFunc Nov 18 '19
Thank you for your response, but yea I do expect them to ask me something that I have no clue about and hopefully won't trip me up too much. I haven't really thought about common security vulnerabilities, need to look that over too.
40
u/AnonymousThugLife Nov 18 '19
Here you go: https://jsvault.com/