Basic JavaScript Interview Questions

Basic JavaScript Interview Questions

Hi everyone! So I had couple of interviews this year for JavaScript software development roles, and I felt its worth writing an article on some of the interview questions I was asked. In this article I will write some of the basic JavaScript interview questions I was asked and the answers to them.

Explain data structure

Data structure is a data organization, management, and storage format that enables efficient access and modification. A data structure is a collection of data values, the relationships among them, and the functions or operations that can be applied to the data.

Simply put, data structure is a defined format/way of storing and managing a collection of data.

List examples of data structures, explain and implement one

some common data structures includes:

  • array
  • linked list
  • double linked list
  • stack
  • queue
  • hash map
  • etc

I will explain and implement a stack.

A stack is a linear data structure that stores data in a LIFO(Last in First Out) manner, i.e. the item added/inserted last is the first item to be accessed. Data in a stack can only be accessed from one end(top of the stack).
A Stack data structure supports only two type of operation namely PUSH(insert/add item) and POP(delete/remove item) operation.


class Stack {
    constructor() { = -1; = [];

    pop = () =>{
            return null;
        let poppedItem =[]; =;
        return poppedItem;

    push = (item)=>{[] = item;

    getTop = ()=>{

let myStack = new Stack();

console.log(myStack.getTop());//output 17
console.log(myStack.getTop());//output 34

Explain Closure with code example

A closure is a function having access to the parent scope, even after the parent function has closed.

var add = (function(){
    let accumulator = 0;
    return function(value){
        return accumulator+=value;

console.log(add(3)); //output 3
console.log(add(5)); //output 8
console.log(add(7)); //output 15

Closure makes it possible for functions to have private variable. E.g in the code above, the function returned by the anonymous function is still able to access the accumulator variable even though the anonymous function is done executing.

Explain Asynchronicity in JavaScript with code example

JavaScript is single threaded, meaning codes are executed sequentially/synchronously(line by line one after the other). Asynchronous JavaScript enables code execution without blocking the main thread, i.e code execute without blocking/stopping other code from executing immediately while its still running/executing.

code example

new Promise((resolve,reject)=>{
    resolve({data:'hello world'});
//{ data: 'hello world' }

In the code above, console.log("end") executes before the promise even though the promise started executing first. This is because the promise is asynchronous and did not block the main thread allowing console.log("end") to execute while it is executing.

Explain Higher Order Functions.

Higher order functions are functions that take other functions as arguments and/or a function that returns a function.
code example

function logger(){
console.log("Hello world!");

In the above setTimeOut is a higher other function that takes the function logger as an argument.


I hope you find this article useful and it helps you prepare for interview.
If you like the content, feel free to start in touch, follow me on twitter

About the Author:

💻 Fullstack developer (web & mobile). 📖 Part time tutor. ❤️ {“writing”: “enthusiast”}


Best, Charles. (2020). Basic JavaScript Interview Questions. Available at: [Accessed: 2nd November 2020].

Share this on...

Rate this Post: