JavaScript Interview Questions

Want to become an expert in cracking JavaScript interview questions/Front end interview questions?

Start with practicing the questions below. Whether a question involves multiple choice or live coding, we will give you hints as you go and tell you if your answers are correct or incorrect.

After that, take our timed public JavaScript Interview Questions Test.

To use our service for testing candidates, buy a pack of candidates.


1. Ensure
JavaScript Language Public

Implement the ensure function so that it throws an error if called without arguments or the argument is undefined. Otherwise it should return the given value.

Easy  
3min
ECMAScript 6
 


  •   No arguments: Wrong answer
  •   Truthy argument: Wrong answer
  •   Falsy argument: Wrong answer

2. Remove Property
JavaScript Language Public

Implement the removeProperty function which takes an object and property name, and does the following:

If the object obj has a property prop, the function removes the property from the object and returns true; in all other cases it returns false.

Easy  
7min
ECMAScript 6
 


  •   Property removed: Wrong answer
  •   Correct return value: Wrong answer

3. Check Digit
JavaScript Strings Public New

Your company assigns each customer a membership ID, and you are implementing a check digit for those IDs.

The check digit should be calculated by adding up all digits in each membership ID. If the result of the sum is a number with more than a single digit, another iteration is required, and the digits of the result also should be added together. This process should repeat until a single-digit number is calculated.

For example, for the membership ID "55555" the sum of all digits is 25. Because this is not a single-digit number, 2 and 5 would be added, and the result, 7, would be the check digit.

Easy  
10min
ECMAScript 6
 


  •   Example case: Wrong answer
  •   Single iteration required: Wrong answer
  •   Two iterations required: Wrong answer
  •   Multiple iterations required: Wrong answer

4. Date
JavaScript Strings Public

Write a function that converts user entered date formatted as M/D/YYYY to a format required by an API (YYYYMMDD). The parameter "userDate" and the return value are strings.

For example, it should convert user entered date "12/31/2014" to "20141231" suitable for the API.

Easy  
10min
ECMAScript 6
 


  •   Example case: Wrong answer
  •   Two-digit month and day: Wrong answer
  •   One-digit day: Wrong answer
  •   One-digit month: Wrong answer

5. Image Gallery
JavaScript DOM manipulation Public

An image gallery is a set of images with corresponding remove buttons. This is the HTML code for a gallery with two images:

<div class="image">
  <img src="https://goo.gl/kjzfbE" alt="First">
  <button class="remove">X</button>
</div>
<div class="image">
  <img src="https://goo.gl/d2JncW" alt="Second">
  <button class="remove">X</button>
</div>

Implement the setup function that registers a click event handler and implements the following logic: When the button of class remove is clicked, its parent <div> element should be removed from the gallery.

For example, after the first image has been removed from the gallery above, it's HTML code should look like this:

<div class="image">
  <img src="https://goo.gl/d2JncW" alt="Second">
  <button class="remove">X</button>
</div>
Easy  
10min
ECMAScript 6
 


  •   Example case: Wrong answer
  •   Remove single image: Wrong answer
  •   Remove multiple images: Wrong answer

6. Closures
JavaScript Bug fixing Closures Public

Fix the bugs in the registerHandlers function. An alert should display anchor's zero-based index within a document instead of following the link.

For example, in the document below, the alert should display "2" when Google anchor is clicked since it is the third anchor element in the document and its zero-based index is 2.

<body>
  In my life, I used the following web search engines:<br/>
  <a href="//www.yahoo.com">Yahoo!</a><br/>
  <a href="//www.altavista.com">AltaVista</a><br/>
  <a href="//www.google.com">Google</a><br/>
</body>
Hard  
15min
ECMAScript 6
 


  •   Example case: Wrong answer
  •   Duplicate links: Wrong answer
  •   Various links: Wrong answer

7. Loop
JavaScript Bug fixing DOM manipulation Public

Function appendChildren should add a new child div to each existing div. New divs should be decorated by calling decorateDiv.

For example, after appendChildren is executed, the following divs:

<div id="a">
  <div id="b">
  </div>
</div>

should take the following form (assuming decorateDiv does nothing):

<div id="a">
  <div id="b">
    <div></div>
  </div>
  <div></div>
</div>

The code below should do the job, but for some reason it goes into an infinite loop. Fix the bugs.

Hard  
15min
ECMAScript 6
 


  •   Example case: Exception
  •   Appending divs: Exception

If you feel ready, take one of our timed public JavaScript Interview Questions tests:
  • ASP.NET (Core) MVC, HTML/CSS, JavaScript, C#, and SQL Online Test (Easy / Hard)
  • ASP.NET Web Forms, HTML/CSS, JavaScript, C#, and SQL Online Test (Easy / Hard)
  • HTML/CSS and JavaScript Online Test (Easy / Hard)
  • HTML/CSS, JavaScript, and Bootstrap Online Test (Easy / Hard)
  • HTML/CSS, JavaScript, C# Algorithms, and SQL Online Test (Easy / Hard)
  • HTML/CSS, JavaScript, C#, and SQL Online Test (Easy / Hard)
  • HTML/CSS, JavaScript, Java Algorithms, and SQL Online Test (Easy / Hard)
  • HTML/CSS, JavaScript, Java, and SQL Online Test (Easy / Hard)
  • HTML/CSS, JavaScript, PHP, and SQL Online Test (Easy / Hard)
  • HTML/CSS, JavaScript, Python Algorithms, and SQL Online Test (Easy / Hard)
  • HTML/CSS, JavaScript, Python, and SQL Online Test (Easy / Hard)
  • HTML/CSS, JavaScript, Ruby, and SQL Online Test (Easy / Hard)
  • JavaScript Online Test (Easy / Hard)
  • JavaScript and SQL Online Test (Easy / Hard)
  • TypeScript and JavaScript Online Test (Easy / Hard)
Not exactly what you are looking for? Go to our For Jobseekers section.