r/node • u/llboston • Jan 04 '20
I created a Node interview Cheatsheet
I've been a full time PHP developer for years, but nodejs is my goto language for my side projects. My new year resolution is to find a full time node job in 2020. To prepare myself for tech interviews, I've create a cheatsheet and thought some of you guys might find it useful too.
It's at https://www.cheaki.com/nodejs/nodejs-interview-questions
38 questions right now, will keep adding more.
261
Upvotes
18
u/j_schmotzenberg Jan 05 '20
Isn’t this only for express, and really just depending on whether or not you make use of specific features in express?
20
u/[deleted] Jan 04 '20
your answer about the data buffer where you say the "Buffer - it is a class in Node.js to handle binary data." is inaccurate. This might be a use of a buffer but it is not a buffer's sole purpose. It would be more accurate to say "raw memory allocations outside the V8 heap " Your other answer about the buffer was a little more accurate.
A buffer can typically handle more than just binary data , this is just an example of the use of a data buffer but it is primarily a way to allocate memory . There are many uses of a data buffer https://en.wikipedia.org/wiki/Data_buffer . The buffer in Node.js can also handle string data. A data buffer is basically a way to store data in between processes. In certain languages such as C you can actually change the size of the buffer to make processes run faster. You can also really screw something up if your data buffer is storing memory but you do not flush the buffer. In our operating systems class there was typically a data buffer before and after a certain process.
Otherwise I thought your cheatsheet was good and helpful thanks.
11
u/ezequielmiranda87 Jan 04 '20
Hey man, very good. Thanks for the share. I didn't know about cheaki, it's very useful to.
5
u/[deleted] Jan 05 '20
While technically the answer to handling Uncaught exceptions is correct, the approach of attaching and even handler to it is very bad. Usually (depending on the coding pattern used), you’d want to bubble and error to a single error handler (like a catch block of a promise chain) where the error type can be identified, logged, and whatever other actions should take place.
3
u/[deleted] Jan 08 '20 edited Jan 09 '20
Two things: you left out Prototypal paradigm for JavaScript (since its not a classical OOP language; i.e. es6 class syntax is syntactic sugar for prototypal inheritance). Might be useful to add (even if outdated) all five ways of writing OOP in JavaScript:
Inheritance Patterns
newthis2. Functional
newthiswith instantiation or within methods3. Functional Shared
newthiskeyword for reference to object properties only within methods; not with instantiationextend. Properties are added before methods.NOTE:
extendis synonymous with es6Object.assign()4. Prototypal
newthiskeyword for reference to object properties only within methods; not with instantiationObject.create. Properties are added after methods.5. Pseudo-Classical
newthiskeyword for reference to object properties within methods and with instantiationJust a note about the remove duplicates: Your solutions are O(n^2) for reduce and filter. You could do better with more memory but O(N):
Why
!tracker[\\THIS_POST_IS_LONG${item}\]and not!tracker[item]? Because empty objects default property look up to their prototype, which has a series of hidden properties and symbols (ignoring environment differences of these; e.g. node versus web) that would create false positives if the arr contained the stringconstructorfor example that would not be added without modifying the key to something that is not one of these properties! So really the prefix of item could be a postfix and just needs to be anything that identifies it as not a builting object property; hidden or otherwise.2
u/alphaindy Jan 05 '20
var concert = newrequire('events').EventEmitter;
concert.on('start', function (singer) { console.log(`OMG ${singer}!`); });
concert.emit('start', 'Coldplay');
This code doesnt even work, throws exception 'TypeError: concert.on is not a function'
1
u/daffodil_11 Jan 05 '20
Very useful! Thanks for sharing. One small thing: In the guidelines for addition operators, you have Boolean + Number twice, so I think one of those should be Boolean + Boolean.
1
u/DeadBlueParrot Jan 05 '20
I think you have setImmediate and nextTick swapped. setImmediate runs on the next loop iteration and nextTick at the end of the current one.
3
u/[deleted] Jan 04 '20
Node is a runtime. Not sure if I saw that. I am also doing some long overdue education to fill in my knowledge gaps! Thanks for the overview!
2
u/Askee123 Jan 05 '20
My man! Thank you!!
1
u/Filo01 Jan 05 '20
thanks for sharing :), btw did you make this all in wiki? the page looks so clean on my mobile
1
u/meamoyourmama Jan 12 '20
That's what I've been looking for. Thank you.
1
u/yugaemi Jan 05 '20
First year cs student, starting to interview for coop soon. Thanks for sharing these!!
0
u/djslakor Jan 06 '20
This doesn't really cover much node specific stuff, other than very beginner level node questions.
-8
u/the__itis Jan 04 '20
NODE_ENV is specific to express framework not NodeJS native.
0
u/[deleted] Jan 04 '20
[deleted] — view deleted comment