Top 10 Common Questions for Any JavaScript Interview

We can quickly agree that JavaScript interviews can be cruel and painstakingly hard. Hence, we should expect that the interviewer’s questions could cover anything from topics on the new JavaScript, the old JavaScript, to the browsers, to  HTML, algorithm questions, or even the data structure. Every particular framework of issues and concepts under which JavaScript maybe connected to can be covered by the interviewer. 

So, before going to any JavaScript interview, it is essential to be prepared. Here are some commonly asked questions for your next JavaScript interview. Beginners will find these tidbits of information handy.

“Let”, “Var” and Scoping

Q: Can you explain the difference between “Let” and “Var”?

A: Yes. I can cite three differences.

First, let has block scoping. In contrast, var has functional scoping in Js.

Second, we can re-declare the reassigned variable with var. In let, however, we cannot re-declare the reassigned value.

The last thing I can think of is that var directly assigns its global variable to window object. On the other hand, let gets assigned to an invisible declarative environment that works similar to global.

The question below is a possible follow-up question to the above.

 

Q: Do you know the two types of scoping? You mentioned earlier how it works with let and var. Can you give a short description of each?

 

A: We mainly have two types of scoping, namely Global Scoping and Local Scoping. To summarize, if we declare something out of every {}  and every function, that is called Global Scoping. On the other hand, Local Scoping happens if we declare something inside {} or inside a function. That variable can now, thus, be considered as locally scoped.

Equal Signs

Q: Can you explain the difference between triple equals signs, “===”, and double equals signs, “==”, in JavaScript? 

 

A: Both signs are equality operators, which means that they would compare values to the left side and the right side. The triple equal sign is a strict equality operator while on the other hand, the double equals sign is coined as an equality operator.

 

Now the difference is when you use the double equal sign, it would just compare the value and it does not resemble the type. In comparison with the triple equal sign, it compares both value and type.

The Difference of “Let” and “Const”

Q: Can you discuss the difference between the keywords “let” and “const”?

A: “Let” and “const” are both used to describe a variable.

Both are signals. Let signals that the variable may be reassigned. It may be through a counter loop or a value swap in an algorithm. It signals that the variable can only be used in the block from which it is defined in which is not most of the time the entire containing function. 

In contrast, Const signals that the identifier will not be reassigned.

ES6

Q: What is the use of arrow functions introduced in ES6 as a new syntax for writing JavaScript?

A: It simplifies the function and thus would consequently save the developers time. It is also known to be the most popular feature of ES6. Arrow functions can also be called fat arrow functions. It uses a new token, =>, thus, the name fat arrow. They work like a one-line mini function, and by utilizing such, we can avoid using the function keyword, return keyword and curly brackets. Using this function helps our work by making the code more concise. It also simplifies our function scoping.

Function Declaration and Function Expression

Q: Can you discuss the difference between function declaration and function expression?

A: The main difference between the two is the time of which each load. If it loads before any code is executed, it is a Function Declaration. But if it loads when the interpreter reaches that line of code, it would basically be a function expression.

Another notable distinction is that function declarations are raised to the top of the other code. In contrast, function expressions are not raised. This allows the latter to retain the copies of the local variables coming from the scope from where they were defined.

Q: What is promise in JavaScript?

A: A promise is considered as in object in JavaScript, which may result to a single value within sometime in the future. It can either be a resolved value, or if not resolved, then there could be some technical reason like an occurrence of a network error. 

A promise can be categorized into three possible states, namely: fulfilled, rejected, or pending. The users of promises in JavaScript can attach callbacks so that it can handle the fulfilled value or the reason for any possible rejection. As soon as the promise instructor is invoked, the promises will start doing whatever task that has been given to it.

Closure in Javascript

Q: What do you know about closure in JavaScript?

A: The combination of a function bundled together or enclosed in relation to its surrounding state or lexical environment is called a closure. To put it in simpler words, a closure can give access to an outer function’s scope from an inner function. At every function creation time, wherein a function is created, a closure is also consequently being created.

Closures have practical uses since they can let you associate data with another function that operates on that data. There can be comparisons with object-oriented programming, wherein such objects allow the programmer to associate data with one or more methods; as a result, there is closure.

SetTimeout and SetInterval;

Q: What is the difference between setTimeout() and setInterval in Javascript?

The only notable distinction between the two is that in setTimeout(), it triggers the expression only once. In contrast, setInterval continuously triggers the expression regularly after the given interval of time.

Note that the above possible questions are only objective but would be a good starting point for beginners. For the advanced interviewees, the technical aspects of each above-mentioned possible concepts could be asked. Now that you know some possible questions for your next JavaScript interview, we hope you feel more confident about it. Best of luck!

We will be happy to hear your thoughts

Leave a reply

Coders Eye - Web Dev Tutorials and How-To Guides for Beginners
Logo
Enable registration in settings - general