loading...

70 JavaScript Interview Questions

Mark A 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... [Read Full]
pic
Editor guide
 

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! :)

 

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!!!

 

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!

 

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

 

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?

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

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

Your welcome. Thanks, again for finding my mistake.

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 ?

 

Great article, well done! πŸ‘

If I was asked any of these at a job interview, I couldn't answer a single one πŸ‘

 

Thanks Kiss 😁

 

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.

 

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 ;)

 

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" ;)

 

I edited it just now. Thanks.

 

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.

 

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.

 

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.

 

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]
 

β€œ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.

 

Thanks for telling me this little problem 😁

 

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); ?

Thanks again 😁

 

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.

 

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?

 

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 :)

 

Question #26

var li = document.querySelector('.list-group > li');

Probably here should be querySelectorAll instead of querySelectorπŸ™‚

 

Thanks 😁, my bad.

 

Hi, I enjoy reading our article, though I found some code that you might wanna check:

In the IIFE section, these examples does not look like valid IIFEs to me;

(() => {

});

const utility = (function () {
return {
//utilities
};
})

Also this function a bit further down is not invoked:

const graphUtility = (function () {
function createGraph() {
// createGraph logic here
}
function drawGraph() {
// drawGraph logic here
}
return {
createGraph,
drawGraph
}
})

 

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.

 

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.

 

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;
 

Thanks man, I totally miss that one, hahaha

 

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

 

Thanks, yea Hoisting is pretty fun to learn

 

These are great, thanks for sharing!

 

No problem man, and btw Thanks 😁

 

Well done, it is helpful

 

Thanks 😁

 

Awesome!!! πŸ‘πŸΏ
Gratitude πŸ™πŸΏ
Stars ✨

 

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.

 
 

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

 

Great article. Great article !!!!

 

Thanks 😁😁😁

 

Awesome, well done mate!

 

Thanks mate! 😁

 

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

 

No Problem man and Thanks πŸ˜ƒ!

 
 

Glad you like it 😁

 

Very detailed answers

 

Thanks man!

 

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.

 

Thanks man for pointing that one out.

 

This is a gem, thanks for writing this!

 

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

 

Thanks man for pointing that one out hahaha

 

Sheesh. Thanks for the write up but good Lord is this intimidating. Lol. Maybe it's more a reality check.

 

This is great stuff

 

Thanks πŸ˜ƒ!

 

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

 

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

 

"This is a long one", this is a nice one ! thanks. My favorite is the 14, tricky question that seems quite simple but there are a lot things to say.

 

Thanks man! Glad you like it 😁

 

Great article. Well written πŸ‘

 

Thanks

 
 

Thanks! Glad you like it 😁

 

Great article!!

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

Thank you!

 

No problem man! And Thanks.

 

Great list! Thank you for the efforts and time you took to collect them.πŸ’™πŸ’™

 
 

Another crazy way for isEven :)

function isEven(num) {
  if (num === 0 || !Number.isFinite(num)) {
    return false;
  }
  return !String(num / 2).includes(".");
}

 

This was so helpful! Thank you so much!

 

Thanks Mark for this beautiful compilation!

 

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...

 

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

 

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

 

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

 

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

 

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

 

Thanks, Glad you like it. πŸ˜ƒ

Code of Conduct Report abuse