Tricky JavaScript interview questions and answers

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments

I'm glad that these questions aren't as common anymore. It's just programming trivia that never comes up in practice and doesn't test whether you are a good programmer or not. Serious recruiters don't use them, and you should not feel bad if all of this feels incomprehensible and pointless, because it is.

👍︎︎ 4 👤︎︎ u/dada_ 📅︎︎ Dec 05 2017 🗫︎ replies

console.log({} + {}) giving me [object object] what is that? I have never seen that before.

👍︎︎ 2 👤︎︎ u/didiben 📅︎︎ Dec 05 2017 🗫︎ replies

I have no clue how to consider myself on a JS scale yet. Can we get a proven badass JS-er opinion on how much this test says about your JS skills compared to what you actually need to know to be good at a JS these days?

👍︎︎ 2 👤︎︎ u/uCbbb 📅︎︎ Dec 05 2017 🗫︎ replies

I just randomly clicked at the end and OP used a slice trick to get the length of the arguments Array-like object. It actually has a length property so you don't need the tricks.

Edit* scrolling back to the x[x](01) part - A better explanation is it doesn't try to convert 01 to a string it converts 01 first to a decimal number since it's an octal number (starting with 0) then it gets converted to a string.

👍︎︎ 1 👤︎︎ u/METALz 📅︎︎ Dec 05 2017 🗫︎ replies

He didn't explain the prototype stuff well. For anyone confused:

'random string'.__proto__ === String.prototype
'random string'.__proto__.__proto__ === Object.prototype

The constructor functions are String and Object, but it's their .prototype property (functions are themselves objects, so they can have properties) that holds an object with all the methods/properties that 'random string' may inherit.

👍︎︎ 1 👤︎︎ u/NoInkling 📅︎︎ Dec 06 2017 🗫︎ replies

This guy is great!

👍︎︎ 1 👤︎︎ u/thickoat 📅︎︎ Dec 06 2017 🗫︎ replies
Captions
hi everybody today we are going to look at the top 10 P artists the JavaScript interview questions they are tricky there are they're confusing and the answer of these questions is never what you expect it to be the problem is sooner or later we all get one of these questions and when we do we just want to pull our hair out so stay tuned to the end of the tutorial because I will explain why do people ask such questions and why would you want to ask such question in the interview so welcome to tech say tutorials all right so here's the first question and it's an easy one so what is the answers of this when I do console.log now I want you to just think about it well pause the video think about it confident answer and then tell your answer of it the one I'm gonna give it to you alright so I hope you have an answer for me and so this is how it works when you use a plus sign it usually works on a number two numbers where you add two numbers or you have strings right what can catch strings otherwise it will have to typecast so it will typecast to string and so what it will do is it will try to convert an empty array into a string and when you convert empty array into a string you get an empty string and to prove it if I do this console.log string this is how you do typecast and this so if I run it in a console it gives me an empty string and I can prove it so if I just do this and run it it would also give me empty string so it's basically empty string plus empty string is an empty string empty array plus an empty array is an empty string now you might get similar answer where you they'll give you something like this an empty object and array empty array or empty object plus empty object so you you have to do the same thing and if you cannot explain it you don't let say if you don't know the answer to a certain type casting then you would just simply say well first I would convert this into a string and this into a string and add try to add it together and see what happens that would be acceptable answer you don't have to have an exact answer as long as you understand the concept alright so here's the second question what is the result of this console.log so you're a function call a and then here you have a sense sentence which is being printed out as a console so again just pause the video think about for a few second and then I'll give you the answer all right so let's try to understand this so first of all let's look at this function as a simple function that simply returns hello no matter basically no matter what you pass it would return hello right all right so then look let's look at line 5 where it says sentence equal to a and hi now this is what is it called tagged templates where if you have a function and you put a template strings next to it it will be consider as an argument to this function so as if as if like if I do this this I would pass and so if I did this if I run this function again since it's not taking any input it would just return hello so actually console.log if this would be hello and hi would be ignored and if you want to look at more in detail what tagged templates are I have a tutorial on it I'll provide a link here all right the third question is take any webpage and make all its content editable so for example and such that I can just click on anything here for example and I can convert it into texted pedia my own website I don't have to change much here how would you able to how would you do that using javascript so the end of the answer that the question is I can have a div with some content say hello and inside I can say content Eddie table equal to true and when I render it I would get hello obviously but I can actually change it here because this content editable equal to true so let's say if I take this Vicki PDF page and I want to make the entire web page editable all I have to do is if I go to inspect element and in the console I would say document dot body which my entire document and content editable equal to true and as soon as I do that and close it now I can actually go here and start changing to Tex it PDF the free Texas tutorials matter I can make my own website basically so this is how you do it it's a cool trick that you can impress your co-workers if they don't know it ok so the next question is and this is a trickier one what is the answer to this so I have a function caller ah an object X and this Y is being passed in its method as an argument so if I do X dot method and Y and some argument what would be the answer again pause it and really try to see what the result might be all right so the answer to this question is - and the reason it's - is you have an object called X which has a method which is a function so this function so if I call X dot method which means it's calling this method which means it's calling this function now you're passing two arguments Y and one Y is nothing but this so inside of this method it says argument 0 so argument arguments object is basically whatever arguments you have if you don't know what arguments are so inside a function when I can say arguments which will be like an early like object which holds all the arguments so this would hold Y and 1 and then the first element would be Y and it would execute this function so it will actually execute Y and so whatever Y gives you the answer that would be the console.log so Y simply says this dot let now you might think that this lawn this dot length is this length here so the answer should be 5 because arguments is an array like object you this really mean arguments and the length you know the length of the array which would be 2 because you you have two arguments so de and then that's a confusing part that you need to know that this would be the length of the arguments again it's a really tricky question you can play this trick on your friends as well all right so now let's look at this next one it's a simple one but a tricky one too so pause the video and I'll tell you the answer all right so the answer answer to this question is 1 and that is because first of all X is a string which is called constructor and if I and so when I do this X X which means I'm trying to find the property X of X and I can substitute to this which mean instructor or I can call it something like this right as well so I'm trying to find the property constructor of X now X is a string now if you if you can you can create string with a literal or you can create as an object as well so let's say if I do I'm gonna comment this out here and I'm gonna create an a string object so if I say let's say Const X equal to new string and I can say constructor and if I console.log it I would get string object and if I expand it I would say its prototype and inside his prototype I would see constructor and this is one of the properties right so if I do console.log X dot construct turn and run it again I would get its a function string which created this function so now we already know that this part is nothing but a function string so which means X X is nothing but a string function so whatever I pass to this would be converted to string so if I do X X and execute this function with this argument it will try to convert 0 1 into strength and when you do that you will get one if I run this I would get I hope you're still enjoying this video all right so before we move to the next question I just have a very quick announcement to make and please hear me out you know if you're enjoying this video please hear me it's a short announcement I won't take a lot of time and it's very important for me at least YouTube has changed their policy and they're constantly changing and one of the things they're doing is they're changing their policy toward the content where they should provide advertisements and that is because a lot of kids videos they're they're create their youtubers who would put really bad content on the kids kids videos you know bad words violence and all kind of bad stuff and YouTube wants to control it and then what they are saying is if you put those kind of stuff out there we are we're gonna restrict all the advertisement on it so automatically or your heads would go down and you know you'll be punished for it so they have an automatic system that just whenever you upload a video it will scan through it and determine that if this video is not appropriate for advertiser why am i why am I telling you this because unfortunately from last three or four weeks any video that I release getting this tag that this is not appropriate for viewers or for Energizer's so it looks something like this I release this video recently and it says this yellow symbol you see that means it's not gonna be monetized which means there will be a limited viewers on here and there is a way to actually review it saying that hey look you need to really view this because automatic system that if there's some problem here because I don't really my video is not what you think it is but what they are saying that you need to have thousand views within seven days for them to even consider to relook at it where some some somebody would physically look at this video and so this is really frustrating not only for me but a lot of youtubers I understand you oops objective but it's becoming really confusing and I it's kind of demotivating me to put videos on YouTube so what I what I want you to do is if you can please if you enjoy my video please like the video and just provide a short comment if you do that then YouTube would think that this video is important and it would because of the positivity of it because of positive thumbs ups it would remove this flag from yellow to green and if you do that for my next couple of videos I would really appreciate it and I really appreciate your help I usually don't ask for such thing but I'm just really frustrated because they just keep doing it and and it just annoying alright so our next question is this when you do add when you add point one and point two what is the answer again as I said it's not what it seems to be so whatever answer that I mean if you unless you know this question and you already know the answer just pause the video and think about it and alright so the answer is if I run this the answer is this Oh point three zero zero zero zero and the fourth so there are 14 digits after floating point and that is because in in JavaScript or for any other languages doing the floating point addition is very done and that is because the decimals are in base 10 and the computer only understand base 2 so you have to do a lot conversion and because of that you'll start you'll get this precision error and there's some other the calculation will get this error not every every calculation would get the get this error all right so the next question is this console.log hi dot underscore register approach on the screen discord proton is going to score purple you get it so what is the answer to this pause the video and let me know this is this one is actually easy if you understand prototype chain and that's the trick alright so the answer that this question is high is obviously a string and it's proto is its creator what is hai is created from it's created using string constructor so if I just do this console.log it I would get string now what's created string so there in JavaScript there is an object call object with capital o that constructor creates all the objects so if I run this I would get this constructor which is the empty object as I say see here now what creates object now object is the final top-level constructor there is nothing beyond this so if you try to do this it should give you now so depend on where you are you will get different answer and I have a tutorial on prototype chain if you wanna if you want to look at it in more detail I'll provide a link here alright the next question is a function that returns total number of argument that pass to it and I would not I do not want you to use any loops so for example if I do something like if I have a function call let's say X and if I pass one two three the answer to this if I do console.log here it should return three because I have one two three arguments all right so here's the answer to this question let's write a function call X equal to a function and inside what I will do I would say return array has a function called slice and I can say call this slice function on the arguments object so every function has an object called arguments which has a list of arguments that you pass in but it's like array like object is not completely array so if I do this array and Theia radar slice call it would convert that arguments to an array so now I have an array and if I simply just say hilly ngth length of the array if I return it that should give me the length of the are the arguments if I do console.log X dot X let's say one two three four five this should give me five then it give me five alright so here's the last question so I have an object with three matters XY and Z and then this method simply does log X log Y and log Z so I want to do this a matter chaining where I can say XY and Z and it should print XY and Z this is the least fearless question but I thought I should include this because it's an interesting one so pause the video and come with an answer alright so the answer is all you have to do is after each console log just return a which is the main object so if I do that now if I run this I would get XYZ and the reason is if I return so when I call X here 8rx it does a console log and returns a which means this becomes a and so I can call it Y on it what I call Y it returns a again so this becomes a and I can call Z on it so that's the simple explanation of how again I have a tutorial on matter chaining if you want to check it out I'll provide a link alright so before I say goodbye let's understand why do people ask such via question in intruder I consider the three different reason one reason is flat-out they just want to outsmart you a lot of time interviewer is a little bit ignorant they just want to come up with these tricky questions and they don't know really how to interview people and so they they'll find this kind of questions on the internet or somewhere and then ask you so I think the motivation there is very wrong actually you should never do that to freak other people out this is an interview not a race second question second reason is sometime you know interview or would be asking some normal questions related the project and everything and suddenly they will ask you one of the weirdest questions to throw you off your game what's gonna happen and you it just you just freaked out a little bit so they just want to show you they want to know your temperament how you handle the situation with failures and it's okay to fail it okay to answer whatever answer you know you may not get the the answer right but as long as you explain the process it should be fine they would understand all right so I hope you learned something from this tutorial and if you did please like subscribe and provide a constructive comment thank you you
Info
Channel: techsith
Views: 103,099
Rating: 4.9641228 out of 5
Keywords: javaScript, interview, interview questions, tutorial, java Script, techsith, techsithtube, techsith.com, lecture
Id: QCQVttjblRs
Channel Id: undefined
Length: 21min 0sec (1260 seconds)
Published: Mon Dec 04 2017
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.