DEV Community

Cover image for 70 JavaScript Interview Questions

70 JavaScript Interview Questions

Mark Abeto on January 03, 2020

Hi Guys Good Day and a Happy New Year 🎆🎆🎆! This is a long one, so bear with me for a second or an hour. In every answer for every questi...
Collapse
 
sebbdk profile image
Sebastian Vargr • Edited

It's funny how interviews often focus on memorization these kind of things, which are the easiest things to look up when you need them.

Half of these things i encountered and used without' having to know the right name for what i was doing, so whats the value?

Very rarely do i get asked about my thoughts on MVC, component orchestration, function vs Class based programming, what over-engineering is, interesting problems i have solved and how, or just maybe how i handle differences of opinion in PR's.

Comparatively speaking, having those kinds of discussions seem much more relevant than whether or not i have memorized all the latest programmer pop culture and random terms one might use once every blue moon.


That being said.

This is a nice list to memorize if you wanna play the default interview game.
Which i might in the future, so thanks! :)

Collapse
 
macmacky profile image
Mark Abeto

I feel you man but most of the time memorizing or knowing this things are not about answering an Interview problem or problems but solving a problem you are having with JavaScript and btw Glad you like it!!!

Collapse
 
weeb profile image
Patrik Kiss • Edited

Great article, well done! 👏

If I was asked any of these at a job interview, I couldn't answer a single one 👍

Collapse
 
macmacky profile image
Mark Abeto

Thanks Kiss 😁

Collapse
 
greatgraphicdesign profile image
Alek Vila

Regarding Question 24, I want to really understand "this" so I tested each example in the Console. I found a different result than what you shared for this line...

myFavoriteObj.guessThis();

You wrote that it logs the window object; however, I'm seeing that in normal mode it logs nothing and in strict mode it throws an error. Maybe it is working differently on your browser? I'm using Chrome 81 on Mac.

By the way, I am enjoying studying this post. Thank you!

Collapse
 
macmacky profile image
Mark Abeto

Thanks, for finding my mistake. I edited it just now. No problem man, glad you like it.

Collapse
 
greatgraphicdesign profile image
Alek Vila

Believe it or not, I'm still going through your list and taking notes. This is a very cool post.

By the way, I've cleared my browser cache the graphic is the same. Maybe it's cached on the server side?

Thread Thread
 
macmacky profile image
Mark Abeto

I've changed the object.

It looks like this now.

 const myFavoriteObj = {
     guessThis(){
        function getThis(){
          console.log(this);
        }
        getThis();
     },
     name: 'Marko Polo',
     thisIsAnnoying(callback){
       callback();
     }
   };


`

Thanks

Thread Thread
 
greatgraphicdesign profile image
Alek Vila

Ah, I see the change now. You removed .name from where it used to say console.log(this.name); Thank you!

Thread Thread
 
macmacky profile image
Mark Abeto

Your welcome. Thanks, again for finding my mistake.

Thread Thread
 
kuncheriakuruvilla profile image
Kuncheria Kuruvilla • Edited

Hey , even now i think there is a problem.
Shouldn't it be
this.name = "Ford Ranger";

rather than
var name = "Ford Ranger";

for question number 24 ?

Collapse
 
mvasigh profile image
Mehdi Vasigh

Nice work! Most of these are pretty good. If you're a hiring manager reading this though, I'd caution against asking questions like "is using the + or unary plus operator the fastest way in converting a string to a number?" because it really doesn't matter and you shouldn't make hiring decisions based on one's knowledge of that.

Collapse
 
cytrowski profile image
Bartosz Cytrowski

Great set of questions :) I want to clarify one thing though: "What does the && operator do?" - It does not return last "truthy" or "falsy" value. It returns the last value it has to calculate to determine the truthiness of the whole expression, eg. 0 || 0 || 0 - will return 0 and 1 && 1 && 1 - will return 1. So the statement in the article is not 100% accurate :) Can't wait to see the update ;)

Collapse
 
raashish1601 profile image
Raashish Aggarwal

G.O.A.T

Collapse
 
sashaokey profile image
Alecc

Mark, you did a grate job. I am finding this list very useful. In a way, it even helped me to make the list of questions for our small organisation(I have even sent it to some of our HRs))) So, believe it or not ..It is used now in practical way in the eastern EU))))If being completely serious, I would recommend more Typescript questions. I know this is the JavaScript Int. Q. I really thing < that using of typescript is growing tremendously. Anyway , great Job, Mark. Thank you.

Collapse
 
macmacky profile image
Mark Abeto • Edited

Hi Alecc, I'm really glad that you like it. That's a nice suggestion. I've been using typescript for over two years now and it's really great it makes your JavaScript code more readable and maintainable. I'll make some questions in the future. Thanks and God bless.

Collapse
 
sashaokey profile image
Alecc

Yes,m Mark, that is amazing how fast the Typescript "cases" grow. I mean , two years ago I have the project, where I had one TS file and I do not even remember why. But now. My team just received a source , There were no JS file extension. TS, TSx). I am, actually, just starting with Typescript.

Collapse
 
bgauryy profile image
bgauryy

Great !

Personally, I think that good interviews should be focused on data flows and performance optimization, and asking about certain API's should be only for choosing the right question as an interviewer.
Also, interviewers should understand the difference between someone who is not knowing something, to someone who is not capable of learning something new.

Good luck for everyone :)

Collapse
 
kotikspb profile image
kotik-spb

Hi! Many thanks for the article, it's really very useful)))
And one thing in Question 31:
const result = strs.reduce((acc, currentStr) => acc + str, "");
I suppose you mean "currentStr" instead of "str" ;)

Collapse
 
macmacky profile image
Mark Abeto

I edited it just now. Thanks.

Collapse
 
droutback profile image
DrOutback

“let x = 5;

x = (x++ , x = addFive(x), x *= 2, x -= 5, x += 10);

function addFive(num) {
return num + 5;
}
If you log the value of x it would be 27. First, we increment the value of x it would be 6, then we invoke the function incrementBy5(6) and pass the 6 as a parameter”

Do you mean addFive(6)?

I’m new to js, so I’m probably wrong.

Collapse
 
macmacky profile image
Mark Abeto

Thanks for telling me this little problem 😁

Collapse
 
droutback profile image
DrOutback

Thanks for writing the article. I’m enjoying it.

Also,

reduce.apply(obj1, [1, 2, 3, 4, 5]); // returns 15
reduce.apply(obj2, 1, 2, 3, 4, 5); // returns 15

Did you mean reduce.call obj2, 1, 2, 3, 4, 5); ?

Thread Thread
 
macmacky profile image
Mark Abeto

Thanks again 😁

Collapse
 
udit1994 profile image
Udit Kaushik

Great article. Very informative. For the question 34, 35 and 36. The implementation might not be quite accurate. You might wanna re-check. For example, to map(), we just pass the callback function. While in your implementation above, you are passing both array and callback to the map(). The array will be available as this inside the map(). Please do correct me if i am wrong.

Collapse
 
mohammedasker profile image
Mohammed Asker

I think this is the longest read time I ever see on the internet. Thank you for the article. I'd bookmark for future references.

Collapse
 
ziizium profile image
Habdul Hazeez • Edited

Thanks guys for reading this post.

Thank you for the effort.

EDIT: In Question 5 you wrote:

Image if we have an HTML structure like this.

Did you intend to use the word Imagine instead of Image?

Collapse
 
amirhe profile image
Amir.H Ebrahimi

actually Implement the Array.prototype.map is not too precise for what really wanted to be implemented.

[,1,2,3,].map(console.log) 
//  [empty, undefined, undefined, undefined]

map([,1,2,3,], console.log) 
// [undefined, undefined, undefined, undefined]
Collapse
 
talantbekov123 profile image
Kairat Talantbekov

Great content! My name is Kairat, I'm a freelance self tough js developer. I'm planning to get a job as a Front end developer instead of freelancing.

Question: This article is very helpful for my theoretical knowledge. I'm just curious will I use these terms in my daily job? Seems like preparation for the exam and I will not use this knowledge in work. Or use very rarely.

Collapse
 
sashaokey profile image
Alecc

Thank you a lot. This article helped me once. You have a good style! What about react hooks? especially custom ones? I would like to read one written by You. thank you. And as we discussed already the typescript for react. Because, I think - TS and TSX are in great demand now.

Collapse
 
hoangph271 profile image
Phan Huy Hoàng • Edited

I think there're a mistake here...!

function myFunc() {
  let a = b;
  a = b = 0;
}
myFunc();

Isn't this invalid syntax...?
It should be:

let a, b;
Collapse
 
macmacky profile image
Mark Abeto

Thanks man, I totally miss that one, hahaha

Collapse
 
lannex profile image
Shin, SJ

Great article!
Can I translate it into Korean and post it on my blog?
I'll clarify the source.

Collapse
 
macmacky profile image
Mark Abeto

No Problem man and Thanks 😃!

Collapse
 
yogeshdharya profile image
YogeshDharya

Hey Mark ! Thank u so much for the wonderful blog ! I wanted to share that as of 17th March 2023 00:10 am IST my comment is the 100th one on this blog . Keep enlightening us with your knowledge like this in the future .

Collapse
 
overflow profile image
overFlow

This a beast. Thank you.
The longest. I did not expect the answers at the bottom after the questions.You put in a lot of work here. bigUps.
I am gonna go through every aspect of and concept of the questions you put up. Thank you.
This should help me rank up my abilities.

Collapse
 
affiction profile image
Maxim

Question #26

var li = document.querySelector('.list-group > li');
Enter fullscreen mode Exit fullscreen mode

Probably here should be querySelectorAll instead of querySelector🙂

Collapse
 
macmacky profile image
Mark Abeto

Thanks 😁, my bad.

Collapse
 
prashan81992916 profile image
prashanth • Edited

Hoisting

let and const are hoisted in a different scope but they are in the temporal dead zone. That's why they throw the error 'let variable cannot be accessed before declaration'

Collapse
 
thedotnetweekly profile image
The DotNET Weekly

Nice list, my favorite one is what is hoisting :)

Collapse
 
macmacky profile image
Mark Abeto

Thanks, yea Hoisting is pretty fun to learn

Collapse
 
Sloan, the sloth mascot
Comment deleted
Collapse
 
macmacky profile image
Mark Abeto

Thanks man! Glad you like it 😁

Collapse
 
danieltareke profile image
Daniel • Edited

Well done, it is helpful

Collapse
 
macmacky profile image
Mark Abeto

Thanks 😁

Collapse
 
jsgoupil profile image
Jean-Sébastien Goupil

I like this article, quite the refresher.
However, I think people forget quite a bit about the method bind that can do partially applied function! And it's not mentioned here.

Collapse
 
camfilho profile image
Carlos Augusto de Medeir Filho

Thanks!

Collapse
 
jetsondavis profile image
Jeff Davidson • Edited

Thanks Mark - great cheat sheet! Btw, what does your dog think of the article?

Collapse
 
ankitkanojia profile image
Ankit Kanojia

Great article. Great article !!!!

Collapse
 
macmacky profile image
Mark Abeto

Thanks 😁😁😁

Collapse
 
gharibi profile image
A. Gharibi

Awesome, well done mate!

Collapse
 
macmacky profile image
Mark Abeto

Thanks mate! 😁

Collapse
 
nataliedeweerd profile image
𝐍𝐚𝐭𝐚𝐥𝐢𝐞 𝐝𝐞 𝐖𝐞𝐞𝐫𝐝

I need to brush up on my JS so this will be super helpful for me! Thank you!

Collapse
 
macmacky profile image
Mark Abeto

Glad you like it 😁

Collapse
 
jpelaa profile image
JP

Very detailed answers

Collapse
 
macmacky profile image
Mark Abeto

Thanks man!

Collapse
 
pavelpotapkin profile image
Pavel Potapkin

Thank you for the great article. It must be mistake in 1 question when you provide example of casting null and undefined to Boolean, you cast only null in both cases.

Collapse
 
macmacky profile image
Mark Abeto

Thanks man for pointing that one out.

Collapse
 
mohamedelidrissi_98 profile image
Mohamed ELIDRISSI

This is a gem, thanks for writing this!

Collapse
 
chmiiller profile image
Carlos Zinato

Awesome article! I think that there is an error on the 3rd example of the Set object comments. It should say K and Z instead of "a". Look like a copy paste from the 4th example

Collapse
 
macmacky profile image
Mark Abeto

Thanks man for pointing that one out hahaha

Collapse
 
mmutinda profile image
mmutinda

This is great stuff

Collapse
 
macmacky profile image
Mark Abeto

Thanks 😃!

Collapse
 
pfacklam profile image
Paul Facklam

Thank you for the time and the passion you have spent for this article. It is awesome!

Collapse
 
macmacky profile image
Mark Abeto • Edited

Thanks man, I just put all the things that I learned for the past two years, still I feel dumb with JavaScript

Collapse
 
hozefaj profile image
Hozefa

Great article. Well written 👍

Collapse
 
macmacky profile image
Mark Abeto

Thanks

Collapse
 
matthwfalk profile image
Matze Falk

Great work!

Collapse
 
macmacky profile image
Mark Abeto

Thanks! Glad you like it 😁

Collapse
 
thomasthx profile image
Thomas • Edited

Great article!!

Can I translate this awesome article into a Japanese version to share if you let me do?

Thank you!

Collapse
 
macmacky profile image
Mark Abeto

No problem man! And Thanks.

Collapse
 
islam profile image
Islam Sayed

Great list! Thank you for the efforts and time you took to collect them.💙💙

Collapse
 
osmanyilmaz profile image
Osman YILMAZ

Thank you :)

Collapse
 
freddie_j23 profile image
Freddie J

hi sir salamat sa post, timing nag hahanap pa naman ako ng work ngayon, bale unang web dev job ko

Collapse
 
capscode profile image
capscode

what an amazing post...

Collapse
 
macmacky profile image
Mark Abeto

No problem man, and btw Thanks 😁

Collapse
 
chmiguel profile image
chmiguel

Did you guys notice how the closures concept is working in the "Implement a memoization helper function" question?
BTW, nice set of questions.

Collapse
 
bksun profile image
Sunil Kumar Singh

Thanks Mark for this beautiful compilation!

Collapse
 
miteshkamat27 profile image
Mitesh Kamat

Biggest takeaway for me is the memoization technique. This has surely prompted me to make most of this feature. Thanks buddy for sharing this !!!

Collapse
 
oosharma profile image
Abhishek Sharma

This was so helpful! Thank you so much!

Collapse
 
thuanpv1 profile image
thuanpv1

for the case 59:
let obj = { prop: undefined }
the third method will not work with this object.

Collapse
 
macmacky profile image
Mark Abeto

Hi, yes It will not work because you're setting the value of that property as 'undefined ' value.

Collapse
 
oionos23 profile image
Giannis Saperas

Good job!!! 👏

Collapse
 
ganesh8999 profile image
Ganesh Singh

Bro thanks for this post it really helped to gain knowledge in Javascript :)

Collapse
 
jdnichollsc profile image
J.D Nicholls

Excellent article, thanks for sharing! <3

Collapse
 
ankur_goyal33 profile image
Ankur Goyal

I have read from youtube : namaste js and mdn docs too. Let and const are hoisted, but they console to error(which is different thing). Imp thing is : let and const are HOISTED too

Collapse
 
alin11 profile image
Ali Nazari

Hey. I've translated this post into Persian. I want to thank you a lot!

Here is the link to the post:
ditty.ir/posts/70-javascript-inter...

Collapse
 
lamisazamzam profile image
Lamisa Zamzam

Thank you for writing this for us. However, could you explain the #62 answer a little bit more explicitly? Thanks again.

Collapse
 
arturogascon profile image
Arturo Gascón

Thank you very much for the insight Mark ;D!!!

Collapse
 
macmacky profile image
Mark Abeto

Thanks, Glad you like it. 😃

Collapse
 
tanya22bose profile image
Tanya Bose

Thank you so much for creating this article, helped me a lot during my interview :)

Collapse
 
jimmykimani profile image
Jimmy Kimani

This is so cool, thanks for sharing!