Must Know Javascript Interview Questions
Resumo
No vídeo, o apresentador discute questões avançadas de entrevistas sobre JavaScript, abordando conceitos importantes que geraram feedbacks no vídeo anterior. Ele inicia explicando funções de ordem superior, que são funções JavaScript que aceitam ou retornam outras funções. Exemplos populares incluem os métodos de array .map e .filter, que requerem funções de callback para operar sobre elementos de arrays, sendo assim categorizadas como funções de ordem superior.
Em seguida, o vídeo aborda as arrow functions, introduzidas no ES6, que oferecem uma sintaxe mais curta para escrever funções. Uma diferença chave é que as arrow functions não podem ser usadas como construtores de objetos. Além disso, elas têm a capacidade de omitir as chaves e a palavra-chave return se a função retornar uma única expressão.
O apresentador também analisa um exemplo de código para explicar o comportamento do loop de eventos do JavaScript, destacando como o setTimeout com zero milissegundos não executa imediatamente devido à prioridade da pilha de chamadas sobre a fila de eventos.
Outro ponto abordado são as quebras de linha em JavaScript, que podem causar resultados inesperados devido à inserção automática de ponto e vírgula pela engine JavaScript, especialmente após uma instrução return.
Por fim, o vídeo explica brevemente sobre promessas em JavaScript, que são usadas para lidar com funções assíncronas, como chamadas AJAX. As promessas permitem que o código execute ações após a conclusão de funções assíncronas por meio do método .then.
O apresentador encerra o vídeo incentivando os espectadores a assistirem a outro vídeo sobre questões de entrevistas em JavaScript e a deixarem um "like".
Chat
Entre para conversar com o vídeo.
EntrarPrincipais Pontos
Funções de ordem superior aceitam ou retornam outras funções, exemplos incluem .map e .filter.
As arrow functions introduzidas no ES6 possuem uma sintaxe mais curta e não podem ser usadas como construtores.
O comportamento do loop de eventos do JavaScript pode atrasar a execução de setTimeout com zero milissegundos.
Quebras de linha podem causar resultados inesperados devido à inserção automática de ponto e vírgula.
Promessas em JavaScript lidam com funções assíncronas e permitem ações após a conclusão de funções, usando .then.
Mindmap
Palavras-chaves
Transcrição
N/A hey everyone so a few months ago i did a video on top javascript interview questions which got a lot of engagement and a lot of feedback so i thought why not do a follow-up some of the feedback i got in that last video suggested that the questions were too basic or too simplistic so hopefully the questions that i go over in this one will be a little bit more realistic let's get started number one N/A explain higher order functions in javascript and provide an example this is one of those terms that sound really intimidating and complicated but it's actually simple so essentially higher order functions are a fancy term we used to describe javascript functions that either take in or return other functions so you already know that you can pass in strings numbers objects into javascript functions and because a javascript function is also an object it should come as no surprise to you that you can also pass in javascript functions into other functions we should really have a counter to describe how many times i'm going to say the word function dot map and dot filter are built-in array methods that are extremely popular examples of higher order functions dot map for example loops through each element in an array and returns a new array well how do we tell dot map what we want to do with each element as it's looping through this is why we need to pass in a callback function into dot map in order to tell the function what we want to do with every single element in the array as we're looping through and because dot map takes in a function as a parameter it's called a higher order function N/A number two what are arrow functions and name a key difference between arrow functions and regular javascript functions so arrow functions were introduced in es6 and essentially they're a shorter more concise way to write functions but there are several key differences in an arrow function of course we can get rid of the function keyword but also if the function consists of only a return statement followed by a single line of code we can actually remove the curly braces and can also remove the return keyword because the arrow function will implicitly return also if the function only has one argument we can even remove the parentheses one key difference between regular functions and arrow functions is that you cannot use arrow functions as object constructors so you'll see my second example here that it will throw a type error by the way guys there's obviously a lot more to arrow functions that i haven't covered but these are really just like example interview answers all right number three i'm gonna show you a piece of code and i want you to tell me what you think is going to be logged onto the console when the code is executed [Music] so these types of questions are super popular because they actually test your comprehension and understanding of the concepts rather than just memorizing a bunch of facts so we know that the javascript engine runs through the code line by line the first thing that's going to be output is obviously one we also know that the last thing that's going to be logged will be two since there is a one second delay that none of the other lines have okay so what about the last two lines so the third line has a set timeout of zero so logically it should run immediately right this is kind of a trick question and it really requires an understanding of javascript events and timing so really what's happening is that the javascript event loop it only checks the event queue if the call stack is empty so the call stack takes precedence only when all the functions have finished running does it check the event loop so when we call set timeout with zero milliseconds what we're really saying is hey call the callback function as soon as possible and as soon as the function stack is empty therefore the next thing that will be console logged is four and then after that it will be three number four okay so i'm going to give you another piece of code and i want you to tell me whether or not they are going to return the same thing pause the video and think about this for a second and then come back to me okay so the answer is is no they will not be returning the same thing the first one will return an object and the second one will return undefined so why is that javascript line breaks are another gotcha that you really need to watch out for because semicolons are technically optional in javascript the engine will actually insert one for you right after return statement if it doesn't see anything else within that line so that's why the second function is just going to terminate at the return statement and it won't even bother executing the next few lines all right number five what are javascript promises N/A and name a use case so if you've done any sort of web development um i'm sure you've run into asynchronous functions such as like making an ajax call or like a set timeout and say you want to wait for that asynchronous function to complete before you do something else like load a list of images that you made the ajax call for so essentially what you want to do is wrap your asynchronous function inside of a promise object that way after you call your function with the asynchronous code inside whatever you want to run after that async function completes you can put inside the dot then callback so that was a really oversimplified explanation of promises um but if you want a more in-depth video on promises i actually did one i'm going to link somewhere here or in the description box below alright guys that's all i have for you today if you enjoyed this video be sure to check out the other video that i did on javascript interview questions and give this one a thumbs up alright i'll see you guys later bye [Music] bye
