DEV Community

Cover image for Basic JavaScript Interview Questions

Basic JavaScript Interview Questions

Charles Best on October 19, 2020

Hi everyone! So I had couple of interviews this year for JavaScript software development roles, and I felt its worth writing an article on some of ...
Collapse
 
recursivefaults profile image
Ryan Latta

One alternative to the stack example is to use shift/unshift.

A benefit is it covers adding and removing items, and allows you to treat the index of 0 as the top without worrying about it.

Also, not many people pay attention to those methods so you might even come across as clever for having non-obivous knowledge of JS Arrays.

Collapse
 
jperasmus profile image
JP Erasmus

Using shift/unshift for the stack would not be a very efficient solution when using JS arrays under the hood because that would turn an O(1) action into O(n) since every item in the array would have to update its index every time to perform either of these actions. Pushing onto the end or popping from it is O(1) since only a single item is affected.

Collapse
 
recursivefaults profile image
Ryan Latta

Being able to talk about that makes a better interview.

Collapse
 
grglldz profile image
Guiorgui

Closure is not necessarily a function, it can be any data type.
Closure is just a reference that is in the accessible scope, whose value comes from a scope that is not accessible.

Collapse
 
piotrlewandowski profile image
Piotr Lewandowski

"Closure is not necessarily a function, it can be any data type" not, exactly. According to MDN: "A closure is the combination of a function bundled together (enclosed) with references to its surrounding state (the lexical environment)." (source: developer.mozilla.org/en-US/docs/W...)

Collapse
 
grglldz profile image
Guiorgui

That is not wrong. That's just one aspect of closures.

Thread Thread
 
piotrlewandowski profile image
Piotr Lewandowski

It's wrong when you phrase it like "JUST a reference that" ("just" suggests it's only that, not "one aspect of") when it's clearly not "just a" :) That's what I meant ;)

Collapse
 
darkwiiplayer profile image
𒎏Wii 🏳️‍⚧️

Wrong. A closure is the combination of a function and some references to either values or variables, depending on the language.

It's commonly simplified to just a function that has access to it's calling scope, because it effectively behaves that way in javascript and pretty much any other language that has them.

Collapse
 
drkvogel profile image
Chris Bird

They are things in computer science, sure, but perhaps not used in frontend development very much. Certainly "call stack" and "Memory Heap" referenced by the OP are things that exist, but are not really necessary to do frontend web development. Backend is a different matter...

Collapse
 
great-dev profile image
Great Dev

Hi Charles!
My name is Serhii and I am from Ukraine.
I have just read your post carefully. I see you are very good at web developing.
As a beginner, I really want to learn from an excellent dev like you and make a career of mine.
If you are interest in my desire, please contact me, twentytwentyaugust@outlook.com
Thanks.

Collapse
 
sonnuk profile image
sonnuk

Good Job! Thank you for sharing
you explained concepts with examples, it's good.
Get Some more topics about javaScript:
tekslate.com/javascript-syntax-com...
tekslate.com/javascript-variables-...

Collapse
 
darkwiiplayer profile image
𒎏Wii 🏳️‍⚧️ • Edited

You probably (indirectly) use Hashmaps quite often: V8 uses them to represent objects when it can't find a good way to optimize their layout.

Collapse
 
dverybest profile image
Charles Best

These may not be something you implement/use in your everyday web development, but understanding them can mean you have basic understanding of code execution in JavaScript. Things like the "call stack", "Memory Heap", "callback queue" and "event loop".

Collapse
 
darkwiiplayer profile image
𒎏Wii 🏳️‍⚧️ • Edited

Try saying Asynchronicity five times

By the way: code is uncountable when referring to source code. There is no "codes".