5 Must Know Interview Questions for Javascript!

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
what's going on guys welcome to another video it is 10 47 at night and I am tired but I have a pretty cool video for you today we're doing 5 interview questions for JavaScript just looking at some gotchas just looking at some simple ones some maybe a little bit more difficult but just testing your knowledge of JavaScript I've been asked a lot of these in my experience with whiteboarding whether that was like an online hacker rank test multiple choice answers whiteboarding there might have been logic related to it in a take-home code test that I had but they're really common basically essential JavaScript questions that I think you guys should know so that's what we're gonna review today I'm really tired I've been up since 4 so when I'm doing this video and if I mess up or say something dumb just remember that I'm tired with sacrifice comes meaning and with struggle comes purpose so we're gonna make this video happen if you guys want to see more videos like this hit that subscribe button hit that like button we have a discord come chat with me in the community link for that in the description I have a patreon you want to support an online creator that's trying to help you guys maybe considered me next time shout out to all the patrons that do support the channel by the way appreciate each and every one of you guys I think that's it I hope you guys enjoyed this video I hope you guys learn a thing or two I'm sure you guys will correct me in the comments that's that's how it goes so I'll see you guys in the next video alright first up we'll start with an array question this is a pretty common question just kind of weeds out the beginners we're gonna be doing it with es6 and regular javascript so the question is how do you add something to the beginning of an array and how do you add something to the end of an array so let's do that first here so I'll do my array push add something to the ended array it appends a new item we can actually mouse over this year in vs code pens no elements to an array returns a new length of the array so you want to push the word inde and then we want to add something to the beginning in order to do that you need to use the unshifted like so inserts new elements at the start of the array and then if we console.log this copy this paste this into the air console here you see start ABCD end brand-new array this modifies the original array just keep that in mind it doesn't create a new array it modifies the original array and then you get this output here so let's do it with es6 let's do something a little bit more complicated take a look at some es6 here so how would you do it with es6 well there are a couple ways to do it we could do like this come here so this right here is called the spread operator you can look that up in ESA we do this this to end that will add something to the end or we could do this so you can see still works just the same can you saw these modifications previously here so this would add it at the beginning right so this takes the group of the items and the array and then you're inserting something in front of it this takes two groups items in the array and inserts something after it and then before and after so pretty self-explanatory that was this array question all right next up I've gotten this question before how do you create a private variable in JavaScript there's no real way to do that except to mess with the scope of JavaScript so in order to do that we need to create a variable that lives inside the local scope of a function so what we'll do here we'll create another function here turn function and inside this function well do turn drive it so set this secret variable and then if we console.log it so another function here it's inside of this function scope so you can't access it if we set it to this variable it's at this function equal to this variable then we run this then it will run this which will in turn run this which will in turn return the private variable so let's copy this paste it super secret code so if I don't do that if I just try to run it all work return private we can't actually see the value of it so we won't know what it says we run this and then it just hits this and you see this function so we have to do it the other way by reassigning it and then running that which will run the secret variable alright so I get this question what is the output of this function well this is a little bit tricky has to do with closures here but in short the outputs will be the number three so if we run this it is the number three and so we can we can walk ourselves through this here so we have the function outer and a function inner it's a function inside of a function and then this function runs and then this outer function runs so this is irrelevant up here nothing nothing really happens this is just a distraction that gets overridden here and it gets over and again here so this is actually not doing anything this isn't setting anything this is just overriding this original one here and we have this function inner non plus plus so this number two is outside the scope of this inner which will give undefined there and then you have VAR Dom 3 which will just end up returning so this has to do with closures this function runs which is basically console logging at number three and then this outer function runs here which runs this inner function which gives us this output a little bit confusing just follow the order operations here and you know there's a little bit for a red herring there just to distract you and this is also there to distract you but this not those fuss can't access this so closures all right here's one with a type of type of one what will this return well give you a second it returns string why does it return string let's check to make sure that it does so return string why does it do that it's more about what it goes down to what it I would say compiles down to that's not the right word I can't think of it because it's it's late but if you look at it like this this will make more sense so order of operations we do the inner parentheses first here type of one will give you a number and then type of number will give you string it's actually the same thing string so we can run a step by step type of one gives a number type of number gives a string so that's the step by step process of what's going on here we have one last one here let's take a look at that what will the output here be so we're using this we have an object here Oh object the name John Doe has a method on it which returns this dot name and then we're doing you still see your own identity hero dot get secret identity and I'm a running his still secret identity here oh good secret identity so what will this return let's find out it's explained what's happening all right so we get undefined and then we get John Doe here so we can figure out how that's working here Oh dot get secret identity it's a hero duck its secret identity and then we're running this and that will give us returns dis that name which is John Doe so if we do this instead now we get John Doe twice so we have to rebind here oh here we have to say stick the hero onto stolen secret identity for it to return twice so because we set it to a new variable we have to add that bind so you can see down here if we just run it here that secret identity works by itself because we haven't reassigned it we haven't removed we haven't extracted the hero from it therefore we don't have to use the combined here we need it so we have access to this keyword so that was it those were five common JavaScript interview questions just having to do with a little bit of gotchas now for some people might be easy for some people might be difficult I actually had to figure out the answer right you know I struggle a bit trying to remember and how to think through it and it's even more difficult when you're on the spot so these are just kind of the nuances of JavaScript specifically not so much to do with algorithms but more of how JavaScript is working underneath the hood it's always good to know these things you can debug so hopefully this has been helpful if it has click that thumbs up hit that subscribe button let me know what you guys want to see I'm making a list right now of user and viewer videos what they like to see and make it happen so you guys want to see some tech interview stuff for you otherwise guys in the next video [Music]
Info
Channel: Joshua Fluke
Views: 290,688
Rating: 4.7444906 out of 5
Keywords: joshua fluke, code bootcamp, javascript, how to code, learn to code, how to make a resume, resume tips, code interview, lambda school, team treehouse, javascript interview questions, javascript interview, whiteboard test, programming test, learn javascript, how to learn to code
Id: 6Wzj7kxfRdI
Channel Id: undefined
Length: 11min 40sec (700 seconds)
Published: Wed Nov 07 2018
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.